Created
February 9, 2016 19:48
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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