Created
February 11, 2016 16:25
-
-
Save NEbere/bb56d321f7cf9ebcfeec to your computer and use it in GitHub Desktop.
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) { | |
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