Skip to content

Instantly share code, notes, and snippets.

@Smakar20
Created September 7, 2017 18:41
Show Gist options
  • Save Smakar20/7ad1fb84aea563bc51882daafc3fdd34 to your computer and use it in GitHub Desktop.
Save Smakar20/7ad1fb84aea563bc51882daafc3fdd34 to your computer and use it in GitHub Desktop.
null created by smakar20 - https://repl.it/KoUf/0
/*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.*/
function LongestWord(sen) {
let arr = sen.replace(/[^\w\s]/gi, '').split(' ')
let longest = ''
let len = 0
for(let char of arr){
if(char == ' ') continue
if(char.length > len){
longest = char
len = char.length
}
}
return longest
}
// keep this function call here
LongestWord('fun&!! time')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment