-
Notifications
You must be signed in to change notification settings - Fork 92
/
Copy pathAlphabet Soup
27 lines (24 loc) · 1.91 KB
/
Alphabet Soup
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/***************************************************************************************
* *
* CODERBYTE BEGINNER CHALLENGE *
* *
* Alphabet Soup *
* Have the function AlphabetSoup(str) take the str string parameter being passed *
* and return the string with the letters in alphabetical order *
* (ie. hello becomes ehllo). Assume numbers and punctuation symbols will not be *
* included in the string. *
* *
* SOLUTION *
* The Array has a built-in sort function but String does not. The first step is to *
* convert the string to an Array and sort it in alphabetical order. Then covert the *
* Array back to a string with the join() function. *
* *
* Steps for solution *
* 1) Convert string to an array *
* 2) Sort array in alphabetical order *
* 3) Convert array back to a string *
* *
***************************************************************************************/
function AlphabetSoup(str) {
return str.split("").sort().join("");
}