Created
December 20, 2016 02:48
-
-
Save bflannery/21b945631a167121702ac2090aecd861 to your computer and use it in GitHub Desktop.
Find the Longest Word in a String
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
// Return the length of the longest word in the provided sentence. | |
// Your response should be a number. | |
function findLongestWord(str) { | |
var longestWord = str.split(' ').reduce(function(longest, currentWord) { | |
return currentWord.length > longest.length ? currentWord : longest; | |
}, ""); | |
return longestWord.length; | |
} | |
console.log(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