Skip to content

Instantly share code, notes, and snippets.

@Stefanacef
Last active September 25, 2021 08:58
Show Gist options
  • Save Stefanacef/bd358d710dd694fbf2e7f0505e5dd3a4 to your computer and use it in GitHub Desktop.
Save Stefanacef/bd358d710dd694fbf2e7f0505e5dd3a4 to your computer and use it in GitHub Desktop.
Longest word |Solution | JavaScript
//Return the length of the longest word in the provided sentence.
function findLongestWordLength(str) {
const strSplit = str.split(" ").map((val, i, arr) => {
return val.split("").length;
});
const strL = Math.max(...strSplit);
return strL;
}
console.log(
findLongestWordLength("The quick brown fox jumped over the lazy dog")
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment