Skip to content

Commit a7a00de

Browse files
committed
Reverse words
1 parent 5f321ee commit a7a00de

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

ReverseWords.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
//---Description---
3+
//Complete the function that accepts a string parameter, and reverses each word in the string.
4+
// All spaces in the string should be retained.
5+
6+
//---Examples given---
7+
// "This is an example!" ==> "sihT si na !elpmaxe"
8+
// "double spaces" ==> "elbuod secaps"
9+
10+
function reverseWords(str) {
11+
return str.split(" ").map(word => word.split("").reverse().join("")).join(" ");
12+
}

0 commit comments

Comments
 (0)