Skip to content

Commit

Permalink
Update Length_of_last_word.js
Browse files Browse the repository at this point in the history
  • Loading branch information
godkingjay authored Oct 31, 2023
1 parent e711cba commit 424b62a
Showing 1 changed file with 5 additions and 14 deletions.
19 changes: 5 additions & 14 deletions Easy/58. Length of Last Word/Length_of_last_word.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,8 @@
* @return {number}
*/
var lengthOfLastWord = function(s) {
s = s.trim();


const words = s.split(" ");
return words[words.length - 1].length;
};

const input1 = "Hello World";
const input2 = "Welcome to Hacktoberfest ";
const input3 = "luffy is still joyboy";

console.log(lengthOfLastWord(input1));
console.log(lengthOfLastWord(input2));
console.log(lengthOfLastWord(input3));
s = s.trim();

const words = s.split(" ");
return words[words.length - 1].length;
};

0 comments on commit 424b62a

Please sign in to comment.