Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link
Owner Author

@jamc92 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