Skip to content

Instantly share code, notes, and snippets.

@joker314
Last active March 18, 2017 16:03
Show Gist options
  • Save joker314/c7940bb0cb349ffb7f82ec188cae3ee8 to your computer and use it in GitHub Desktop.
Save joker314/c7940bb0cb349ffb7f82ec188cae3ee8 to your computer and use it in GitHub Desktop.
// Solution below
// Solution below
// Solution below
// Solution below
function longestWord(sentence){
// We have a sentence
// The longest word in the sentence has a length of at least 0
var longest = 0;
// We want to loop through each word in the sentence
var words = sentence.split(" ");
for(var i = 0; i < words.length; i++){
// We want to only update the value of the variable if the new value is bigger
if(words[i].length > longest) longest = words[i].length;
}
// Now we have a final result, let's return it
return longest;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment