Created
September 7, 2017 18:41
-
-
Save Smakar20/7ad1fb84aea563bc51882daafc3fdd34 to your computer and use it in GitHub Desktop.
null created by smakar20 - https://repl.it/KoUf/0
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
/*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