Created
May 16, 2018 14:33
-
-
Save MorenoMdz/3dd6e12b890f9b2005a7c765335d061c to your computer and use it in GitHub Desktop.
Alphabet Soup code challenge
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * This challenge requires you to alphabetically sort the characters in a string. We'll sort the characters using the built-in array sort function. | |
| */ | |
| function AlphabetSoup(str) { | |
| // Convert the passed str into an array of chars with split then sort the array in alphabetical order | |
| var chars = str.split(''); | |
| var sorted = chars.sort(); | |
| // Return the rebuilt string | |
| return sorted.join(''); | |
| } | |
| /* Shorter */ | |
| function AlphabetSoup2(str) { | |
| var sorted = str.split('').sort(); | |
| return sorted.join(''); | |
| } | |
| /* Shortest */ | |
| function AlphabetSoup3(str) { | |
| return str | |
| .split('') | |
| .sort() | |
| .join(''); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment