Last active
May 23, 2018 03:31
-
-
Save denismcdonald/a75a747acecf008796af39727f0195e2 to your computer and use it in GitHub Desktop.
Find the longest word in a sentence and return word length (JavaScript)
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 splitString = str.split(" "); | |
var longestString = splitString[0]; | |
for (var i = 0; i < splitString.length; i++) { | |
if (splitString[i].length > longestString.length) { | |
longestString = splitString[i]; | |
} | |
} | |
return longestString.length; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment