JavaScript Last Word Length Solution

Day 20 / 30 – JavaScript Coding Challenge Today’s problem: Length of Last Word Problem: Given a string containing words and spaces, return the length of the last word. Solution: var lengthOfLastWord = function (s) {     let count = 0;     let i = s.length - 1;     while (i >= 0 && s[i] === " ") {         i--;     }     while (i >= 0 && s[i] !== " ") {         i--;         count++;     }     return count; }; #JavaScript #DSA #CodingPractice #100DaysOfCode #ProblemSolving #FrontendDevelopment

  • No alternative text description for this image

To view or add a comment, sign in

Explore content categories