Skip to content

Instantly share code, notes, and snippets.

@Angelfire
Last active October 17, 2018 01:22
Show Gist options
  • Save Angelfire/f9a4e5f1e28270a527f053cab1f9bd5d to your computer and use it in GitHub Desktop.
Save Angelfire/f9a4e5f1e28270a527f053cab1f9bd5d to your computer and use it in GitHub Desktop.
/**
Challenge
Have the function LongestWord(sen) take the sen parameter being passed and return the largest word in the string. If there are two or more words that are the same length, return the first word from the string with that length. Ignore punctuation and assume sen will not be empty.
Sample Test Cases
Input:"fun&!! time"
Output:"time"
Input:"I love dogs"
Output:"love"
*/
function LongestWord(sen) {
var splitStr = sen.split(' ');
var arrStr = splitStr.map(word => word.replace(/[^A-Za-z0-9]/g, ''));
var longStr = arrStr.sort((a,b) => a.length < b.length)[0];
return longStr;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment