Last active
December 26, 2015 12:19
-
-
Save thetallweeks/7149915 to your computer and use it in GitHub Desktop.
Coderbyte Longest Word in a string
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
function LongestWord(sen) { | |
longest = ""; | |
// code goes here | |
var words = sen.split(" "); | |
for(i = 0; i < words.length; i++) { | |
if(words[i].length > longest.length) { | |
longest = words[i]; | |
} | |
} | |
return longest; | |
} | |
// keep this function call here | |
// to see how to enter arguments in JavaScript scroll down | |
LongestWord(readline()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Fails edge cases (e.g. "a confusing /:sentence:/[ this is not!!!!!!!~")