Solutions 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

Loading...