Skip to content

Instantly share code, notes, and snippets.

@MorenoMdz
Created May 16, 2018 14:33
Show Gist options
  • Select an option

  • Save MorenoMdz/3dd6e12b890f9b2005a7c765335d061c to your computer and use it in GitHub Desktop.

Select an option

Save MorenoMdz/3dd6e12b890f9b2005a7c765335d061c to your computer and use it in GitHub Desktop.
Alphabet Soup code challenge
/**
* 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