Last active
September 5, 2016 02:45
-
-
Save jgresalfi/30899247d2083bcfe2d0d33247b0ca0e to your computer and use it in GitHub Desktop.
Find longest word in a string.
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 strArray = str.split(" "), | |
arrCount = []; | |
for (var i = 0; i < strArray.length; i++) { | |
arrCount.push(strArray[i].length); | |
} | |
return Math.max(...arrCount); | |
} | |
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