Step-by-step solution for Alphabet Soup
View the 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 string into an array of characters
  var chars = str.split("");

  // sort the array in alphabetical order
  var sorted = chars.sort();

  // return the newly sorted string
  return sorted.join("");
         
}
   
AlphabetSoup("coderbyte");                                                   
def AlphabetSoup(str): 

  # convert the string into a list of characters
  chars = list(str)

  # sort the list in alphabetical order
  sortedChars = sorted(chars)

  # return the newly joined string
  return "".join(sortedChars)
    
print AlphabetSoup("coderbyte")  
def AlphabetSoup(str)

  # convert the string into a list of characters
  chars = str.split('')

  # sort the list in alphabetical order
  sorted = chars.sort
  
  # return the newly joined string
  return sorted.join
         
end
   
puts AlphabetSoup(STDIN.gets)   
Top User Solutions
1 hyuil Challenge Score: 10 Cpp
1 Qlogin Challenge Score: 10 Python
2 Sabin Challenge Score: 10 Python
1 emuchynski Challenge Score: 10 Ruby
3 KlaraKathrina Challenge Score: 10 Python
2 junjunparkpark Challenge Score: 10 Ruby
1 cjordanball Challenge Score: 10 JavaScript
4 Corinto Challenge Score: 10 Python
2 EmperorDuny Challenge Score: 10 JavaScript
5 gzamfire Challenge Score: 10 Python
6 mmalkavian Challenge Score: 10 Python
3 GarenLiang Challenge Score: 10 JavaScript
2 lokeshmogra Challenge Score: 10 Cpp
4 beeboop19 Challenge Score: 10 JavaScript
3 cdms0 Challenge Score: 10 Cpp
5 jackgeek Challenge Score: 10 JavaScript
6 escapiststupor Challenge Score: 10 JavaScript
7 hurgadion Challenge Score: 10 Python
4 gutty333 Challenge Score: 10 Cpp
8 scates Challenge Score: 10 Python
9 ricky0309 Challenge Score: 10 Python
7 chrigolex Challenge Score: 10 JavaScript
10 philtroin Challenge Score: 10 Python
3 Bohdan Challenge Score: 10 Ruby
5 sanguookchoi Challenge Score: 10 Cpp
8 mattlarsh Challenge Score: 10 JavaScript
4 zestybmac Challenge Score: 10 Ruby
9 deuzen Challenge Score: 10 JavaScript
1 arjnklc Challenge Score: 10 Java
10 SuprDewd Challenge Score: 10 JavaScript
5 gladysum Challenge Score: 10 Ruby
6 mattfara Challenge Score: 10 Ruby
6 theBestFella Challenge Score: 10 Cpp
7 toasterbob Challenge Score: 10 Ruby
8 SSJ6Porfy Challenge Score: 10 Ruby
9 duncanbb Challenge Score: 10 Ruby
10 kelaiyarao1 Challenge Score: 10 Ruby
7 johne Challenge Score: 10 Cpp
1 ionutforyou Challenge Score: 10 PHP
8 Justification Challenge Score: 10 Cpp
2 tostercx Challenge Score: 10 PHP
9 Zeikar Challenge Score: 10 Cpp
2 danaksim Challenge Score: 10 Java
3 jakmaj Challenge Score: 10 Java
4 mikejagen Challenge Score: 10 Java
5 ph4ntom Challenge Score: 10 Java
6 binfeng Challenge Score: 10 Java
10 anta0 Challenge Score: 10 Cpp
7 Niliyam Challenge Score: 10 Java
8 k8conant Challenge Score: 10 Java
9 nicklivens Challenge Score: 10 Java
10 KSmithson Challenge Score: 10 Java
3 longcheng Challenge Score: 10 PHP
4 torbjornperttu Challenge Score: 10 PHP
5 albionselimaj Challenge Score: 10 PHP
6 teplicko Challenge Score: 10 PHP
7 smcdowell Challenge Score: 10 PHP
8 jetonr Challenge Score: 10 PHP
9 mihainem Challenge Score: 10 PHP
10 khattab Challenge Score: 10 PHP