Skip to content

Latest commit

 

History

History
29 lines (22 loc) · 656 Bytes

reverse-words.md

File metadata and controls

29 lines (22 loc) · 656 Bytes

Reverse words 7 Kyu

LINK TO THE KATA - STRINGS FUNDAMENTALS

Description

Complete the function that accepts a string parameter, and reverses each word in the string. All spaces in the string should be retained.

Examples

"This is an example!" ==> "sihT si na !elpmaxe"
"double  spaces"      ==> "elbuod  secaps"

Solution

const reverseWords = str => {
  return str
    .split(' ')
    .map(word => word.split('').reverse().join(''))
    .join(' ')
}