Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit b768505

Browse files
author
zongyanqi
committed
add Medium_151_Reverse_Words_in_a_String
1 parent d756fe9 commit b768505

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* Given an input string, reverse the string word by word.
3+
4+
For example,
5+
Given s = "the sky is blue",
6+
return "blue is sky the".
7+
*/
8+
9+
/**
10+
* @param {string} str
11+
* @returns {string}
12+
*/
13+
var reverseWords = function (str) {
14+
return str.split(' ')
15+
.filter(w => w)
16+
.reverse()
17+
.join(' ');
18+
};

0 commit comments

Comments
 (0)