Skip to content

Commit 5682909

Browse files
committed
Create Longest Word
1 parent bec9e2f commit 5682909

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

Longest Word

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*************************************************************************
2+
* *
3+
* Using the JavaScript language, have the function LongestWord(sen) *
4+
* take the sen parameter being passed and return the largest word in *
5+
* the string. If there are two or more words that are the same length, *
6+
* return the first word from the string with that length. Ignore *
7+
* punctuation and assume sen will not be empty. *
8+
* *
9+
*************************************************************************/
10+
11+
function LongestWord(sen) {
12+
13+
var arr = sen.replace(/[^a-zA-Z ]/g,"").split(" ");
14+
15+
arr.sort(function(a,b) { return b.length - a.length } );
16+
return arr.shift();
17+
18+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy