File tree Expand file tree Collapse file tree 1 file changed +3
-9
lines changed Expand file tree Collapse file tree 1 file changed +3
-9
lines changed Original file line number Diff line number Diff line change 11
11
* SOLUTION *
12
12
* The Array has a built-in sort function but String does not. The first step is to *
13
13
* 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
+ * *
16
16
* Steps for solution *
17
17
* 1) Convert string to an array *
18
18
* 2) Sort array in alphabetical order *
19
19
* 3) Convert array back to a string *
20
- * 4) Remove comma separators in our string *
21
20
* *
22
21
***************************************************************************************/
23
22
24
23
function AlphabetSoup(str) {
25
24
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("");
32
26
33
27
}
You can’t perform that action at this time.
0 commit comments