Skip to content

Instantly share code, notes, and snippets.

@NEbere
Created February 11, 2016 16:25
Show Gist options
  • Save NEbere/bb56d321f7cf9ebcfeec to your computer and use it in GitHub Desktop.
Save NEbere/bb56d321f7cf9ebcfeec to your computer and use it in GitHub Desktop.
Return the length of the longest word in the provided sentence.
function findLongestWord(str) {
var strArray = str.toUpperCase().split(' ').sort();
var longest = 0;
for (var i = 0; i < strArray.length; i++) {
if (strArray[i].length > longest) {
longest = strArray[i].length;
}
}
return longest;
}
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