Last active
December 24, 2015 05:09
-
-
Save GHowlett/6748375 to your computer and use it in GitHub Desktop.
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
// string input is assumed, punctuation is ignored, and the earliest word wins a tie | |
function getLongestWord (sentance) { | |
var words = sentance.split(/[\s-]+/); | |
words = words.map( function(word) {return word.match(/[\w\d]+/)[0] || '';} ); | |
return words.reduce( function(a,b) {return (a.length >= b.length)? a:b;} ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment