Skip to content

Instantly share code, notes, and snippets.

@GHowlett
Last active December 24, 2015 05:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GHowlett/6748375 to your computer and use it in GitHub Desktop.
Save GHowlett/6748375 to your computer and use it in GitHub Desktop.
// 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