Last active
January 24, 2017 05:18
-
-
Save nareshwar/1d53ec9b3ce3da7923145e945cf018d0 to your computer and use it in GitHub Desktop.
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 SplittedArr = str.split(' '); | |
var longestWord = SplittedArr[0].length; //initiated longestWord with the first element's length of the array | |
for (i = 1; i < SplittedArr.length; i++) { | |
if (SplittedArr[i].length > longestWord) { | |
longestWord = SplittedArr[i].length; | |
} | |
} | |
return longestWord; | |
} | |
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