Last active
March 18, 2017 16:03
-
-
Save joker314/c7940bb0cb349ffb7f82ec188cae3ee8 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// 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