Skip to content

Instantly share code, notes, and snippets.

@mosdevly
Last active August 29, 2015 14:10
Show Gist options
  • Save mosdevly/98385a813e8cd93846b3 to your computer and use it in GitHub Desktop.
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.
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