Skip to content

Commit 73cfcf8

Browse files
committed
Update Alphabet Soup
1 parent ef2f048 commit 73cfcf8

File tree

1 file changed

+3
-9
lines changed

1 file changed

+3
-9
lines changed

Alphabet Soup

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,17 @@
1111
* SOLUTION *
1212
* The Array has a built-in sort function but String does not. The first step is to *
1313
* convert the string to an Array and sort it in alphabetical order. Then covert the *
14-
* Array back to a string with the toString() function. The last step is to remove *
15-
* the commans that separate each character. *
14+
* Array back to a string with the join() function. *
15+
* *
1616
* Steps for solution *
1717
* 1) Convert string to an array *
1818
* 2) Sort array in alphabetical order *
1919
* 3) Convert array back to a string *
20-
* 4) Remove comma separators in our string *
2120
* *
2221
***************************************************************************************/
2322

2423
function AlphabetSoup(str) {
2524

26-
var myArray = str.split("")
27-
28-
myArray.sort();
29-
var newStr = myArray.toString();
30-
31-
return newStr.replace(/,/g, "");
25+
return str.split("").sort().join("");
3226

3327
}

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