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 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
2423function 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}
You can’t perform that action at this time.
0 commit comments