Created
February 22, 2014 22:24
-
-
Save bradoyler/9163347 to your computer and use it in GitHub Desktop.
JS console challenge : find the longest word
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
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