Created
November 17, 2015 02:22
-
-
Save erictleung/0b1f4f43e0f234300129 to your computer and use it in GitHub Desktop.
Find longest word within a space separated 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 splitStr = str.split(" "); | |
var long = 0; | |
for (i = 0; i < splitStr.length; i++) { | |
if (splitStr[i].length > long) { | |
long = splitStr[i].length; | |
} | |
} | |
return long; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment