Skip to content

Instantly share code, notes, and snippets.

@bradoyler
Created February 22, 2014 22:24
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 bradoyler/9163347 to your computer and use it in GitHub Desktop.
Save bradoyler/9163347 to your computer and use it in GitHub Desktop.
JS console challenge : find the longest word
function LongestWord(sen) {
sen = sen.split(' '); // creates array
var nonAlpha = new RegExp('[^a-zA-Z\d\s:]');
var filtered = sen.filter(function(item){
return !nonAlpha.test(item);
});
var sorted = filtered.sort(function(n1,n2){
return n2.length - n1.length ;
});
return sorted[0];
}
console.log(LongestWord("tested th$ l00ngest word !!!!!!!!!!!!"));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment