15/19 I don't understand


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.


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


Thanks. That article explains it well.:smile: