Skip to content

Instantly share code, notes, and snippets.

@nareshwar
Last active January 24, 2017 05:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nareshwar/1d53ec9b3ce3da7923145e945cf018d0 to your computer and use it in GitHub Desktop.
Save nareshwar/1d53ec9b3ce3da7923145e945cf018d0 to your computer and use it in GitHub Desktop.
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