Skip to content

Instantly share code, notes, and snippets.

@jgresalfi
Last active September 5, 2016 02:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jgresalfi/30899247d2083bcfe2d0d33247b0ca0e to your computer and use it in GitHub Desktop.
Save jgresalfi/30899247d2083bcfe2d0d33247b0ca0e to your computer and use it in GitHub Desktop.
Find longest word in a string.
function findLongestWord(str) {
var strArray = str.split(" "),
arrCount = [];
for (var i = 0; i < strArray.length; i++) {
arrCount.push(strArray[i].length);
}
return Math.max(...arrCount);
}
findLongestWord("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