Sorting arrays is a very common problem in computer science, and is well studied for that reason. There are many algorithms —well-defined sequences of steps—each with its own trade-offs and advantages.
Sorting algorithms can be a great introduction to computer science as a theoretical discipline, but for now we’ll focus on how to use Ruby’s built-in sorting library (which implements a few of these algorithms).
.sort! method to sort the values in
my_array. Magic, isn’t it?
my_array in the console.