Skip to Main Content

Length of Last Word

Problem URL:Length of Last Word

My Solution

JavaScript

/**
 * @param {string} s
 * @return {number}
 */

const lengthOfLastWord = (s) => {
  return s
    .split(" ")
    .filter((str) => str.length > 0)
    .pop().length;
};

Let's Connect

Twitter GitHub LinkedIn