Learn

If we were to hand you five books and ask you to arrange them, sorted by title, on a shelf, how would you do it?

Most sorting algorithms assume we are sorting an array of items, which involves comparing any two items in the array and deciding which should come first.

For our books example, if for any pair we always chose the book whose title came first in the alphabet, we could devise a strategy for sorting. These “strategies” are the sorting algorithms mentioned in the previous example. Our job is to decide how to compare two items in the list, and let Ruby decide which strategy to use.

Instructions

1.

What Ruby method could we call on books in order to sort the list of books alphabetically? Try it out in the editor.

Take this course for free

By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.
Already have an account?