Skip to content

Instantly share code, notes, and snippets.

@jamc92
Created April 3, 2016 22:14
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 jamc92/587e6994c76c7a35985be327a25ec26c to your computer and use it in GitHub Desktop.
Save jamc92/587e6994c76c7a35985be327a25ec26c to your computer and use it in GitHub Desktop.
function findLongestWord(str) {
var myArray = str.split(' ');
var arrayData = myArray[0].length;
for (var i = 0; i < myArray.length; i++) {
if (arrayData < myArray[i].length) {
arrayData = myArray[i].length;
}
}
return arrayData;
}
findLongestWord("The quick brown fox jumped over the lazy dog");
@jamc92
Copy link
Author

jamc92 commented Apr 3, 2016

  • findLongestWord("The quick brown fox jumped over the lazy dog") should return a number.
  • findLongestWord("The quick brown fox jumped over the lazy dog") should return 6.
  • findLongestWord("May the force be with you") should return 5.
  • findLongestWord("Google do a barrel roll") should return 6.
  • findLongestWord("What is the average airspeed velocity of an unladen swallow") should return 8.
  • findLongestWord("What if we try a super-long word such as otorhinolaryngology") should return 19.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment