Skip to content

Commit bd484e7

Browse files
committed
lengthOfLastWord
1 parent 832aa5d commit bd484e7

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

lengthOfLastWord.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* @param {string} s
3+
* @return {number}
4+
*/
5+
var lengthOfLastWord = function(s) {
6+
let arr = s.trim().split("").reverse(),
7+
start = 0;
8+
9+
while (arr.length){
10+
let char = arr.shift();
11+
if (char !== " "){
12+
start++
13+
} else {
14+
return start
15+
}
16+
}
17+
18+
return start;
19+
};

0 commit comments

Comments
 (0)