From e7fcccb5bce6d105b4db7846b9908f353dd9d78f Mon Sep 17 00:00:00 2001 From: hamna Date: Mon, 30 Oct 2023 09:39:38 +0500 Subject: [PATCH 1/3] Length_of_last_word(Hacktoberfest) --- .../Length_of_last_word.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 Easy/58. Length_of_last_word/Length_of_last_word.js diff --git a/Easy/58. Length_of_last_word/Length_of_last_word.js b/Easy/58. Length_of_last_word/Length_of_last_word.js new file mode 100644 index 0000000..a5e6ea1 --- /dev/null +++ b/Easy/58. Length_of_last_word/Length_of_last_word.js @@ -0,0 +1,19 @@ +/** + * @param {string} s + * @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)); \ No newline at end of file From e711cba1d2ab4dd5d96b8baec1374a1dd94d383b Mon Sep 17 00:00:00 2001 From: Jarrian Gojar Date: Tue, 31 Oct 2023 08:55:34 +0800 Subject: [PATCH 2/3] Rename Length_of_last_word.js to Length_of_last_word.js --- .../Length_of_last_word.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename Easy/{58. Length_of_last_word => 58. Length of Last Word}/Length_of_last_word.js (90%) diff --git a/Easy/58. Length_of_last_word/Length_of_last_word.js b/Easy/58. Length of Last Word/Length_of_last_word.js similarity index 90% rename from Easy/58. Length_of_last_word/Length_of_last_word.js rename to Easy/58. Length of Last Word/Length_of_last_word.js index a5e6ea1..ab7a1bc 100644 --- a/Easy/58. Length_of_last_word/Length_of_last_word.js +++ b/Easy/58. Length of Last Word/Length_of_last_word.js @@ -16,4 +16,4 @@ var lengthOfLastWord = function(s) { console.log(lengthOfLastWord(input1)); console.log(lengthOfLastWord(input2)); - console.log(lengthOfLastWord(input3)); \ No newline at end of file + console.log(lengthOfLastWord(input3)); From 424b62ac0731ec1b85aa91648c6a3b1b163590e0 Mon Sep 17 00:00:00 2001 From: Jarrian Gojar Date: Tue, 31 Oct 2023 08:56:04 +0800 Subject: [PATCH 3/3] Update Length_of_last_word.js --- .../Length_of_last_word.js | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/Easy/58. Length of Last Word/Length_of_last_word.js b/Easy/58. Length of Last Word/Length_of_last_word.js index ab7a1bc..1b78d3b 100644 --- a/Easy/58. Length of Last Word/Length_of_last_word.js +++ b/Easy/58. Length of Last Word/Length_of_last_word.js @@ -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; +};