Created
April 3, 2016 22:14
-
-
Save jamc92/587e6994c76c7a35985be327a25ec26c 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 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"); |
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