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
Lines changed: 18 additions & 0 deletions
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy