Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 86cbaa4

Browse files
Longest Word
1 parent d9bccbb commit 86cbaa4

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

‎9_Longest-Word/index.js‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Longest Word
2+
// Write a function that takes in a string (sentence) and returns the longest word (excluding all special characters)
3+
4+
const longestWord = str => {
5+
return str
6+
.split(' ')
7+
.map(word => {
8+
return word.replace(/[\W_]/g, '')
9+
})
10+
.sort((word1, word2) => {
11+
return word2.length - word1.length
12+
})[0]
13+
}
14+
15+
console.log(longestWord('Ready..., steady, go!!!!!!!'))
16+
console.log(longestWord('Hey there guy'))

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /