15/19 I don't understand


#1

With books.sort! { |firstBook, secondBook| firstBook <=> secondBook } , I don't understand what it does. They say it returns 1, 0, or -1, but what does the program do with that. I know you do .reverse! on the descending, because I looked on the discussion to try to find an explanation. Please help.


#2

To sort by descending order, we need only change the order of the block:

    secondBook <=> firstBook

This SO thread is a pretty good discussion: http://stackoverflow.com/questions/827649/what-is-the-ruby-spaceship-operator


#3

Thanks. That article explains it well.:smile: