Finally, let’s review what we learned about sorting.

books.sort! do |firstBook, secondBook| firstBook <=> secondBook end

Remember that the above example was how we sorted in alphabetical order.



Use .sort! to sort the fruits array in descending (that is, reverse) alphabetical order. You can use the combined comparison operator (like the example above) or an if/elsif/else statement.

Take this course for free

Mini Info Outline Icon
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.

Or sign up using:

Already have an account?