Last active
August 29, 2015 14:10
-
-
Save mosdevly/98385a813e8cd93846b3 to your computer and use it in GitHub Desktop.
Write a method that takes a string and returns the longest word in it.
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
var longestWord = function(myString) { | |
words = myString.split(" "); | |
longest = ""; | |
for (var word = 0; word < words.length ; word++) { | |
if (words[word].length > longest.length) { | |
longest = words[word] | |
} | |
} | |
return longest; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment