Skip to content

Instantly share code, notes, and snippets.

@ccnixon
Created February 9, 2016 19:48
Show Gist options
  • Save ccnixon/91493fd8f81683513905 to your computer and use it in GitHub Desktop.
Save ccnixon/91493fd8f81683513905 to your computer and use it in GitHub Desktop.
Find the Longest Word in a String: Return the length of the longest word in the provided sentence.
function findLongestWord(str) {
str = str.split(' ');
return str.reduce(function(a,b ){ return a.length > b.length ? a : b;}).length
}
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