Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb768505

Browse files
author
zongyanqi
committed
add Medium_151_Reverse_Words_in_a_String
1 parentd756fe9 commitb768505

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+
varreverseWords=function(str){
14+
returnstr.split(' ')
15+
.filter(w=>w)
16+
.reverse()
17+
.join(' ');
18+
};

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp