Created
January 11, 2017 10:39
-
-
Save mijimoco/9f8e8808fdb9281cd088f68944804ccc to your computer and use it in GitHub Desktop.
Find the Longest Word in an Array
This file contains hidden or 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 arrayofString = str.split(' '); | |
var longestString = 0; | |
for (i=0; i< arrayofString.length; i++) { | |
if (arrayofString[i].length > longestString) { | |
longestString = arrayofString[i].length; | |
}; | |
}; | |
console.log(longestString); | |
return longestString; | |
} | |
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