Skip to content

Instantly share code, notes, and snippets.

@mijimoco
Created January 11, 2017 10:39
Show Gist options
  • Save mijimoco/9f8e8808fdb9281cd088f68944804ccc to your computer and use it in GitHub Desktop.
Save mijimoco/9f8e8808fdb9281cd088f68944804ccc to your computer and use it in GitHub Desktop.
Find the Longest Word in an Array
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