Say I want to sort an array of strings in Ruby in descending order. So for example:
books = ["Charlie and the Chocolate Factory", "War and Peace", "Utopia", "A Brief History of Time", "A Wrinkle in Time"]
I'm currently going through Code Academy's Ruby course and they say to use the following code to achieve this:
books.sort! { |firstBook, secondBook| secondBook <=> firstBook }
However, couldn't this also be done by simply writing the following?
books.sort!.reverse
They both produce the same result on the Code Academy lesson but I was wondering if there what the difference was between the two.