Why put 2 elements



My code works, but I am not clear on why it works. I got everything to function correctly I am just not sure how or why

Replace this line with your code. 
books = ["Charlie and the Chocolate Factory", "War and Peace", "Utopia", "A Brief History of Time", "A Wrinkle in Time"]

I understand that the .sort sorts everything in the block, but why do I need to use two elements if there are 5 books. It was to my understanding that the <=> operator just compared two things and told you 0, 1, or -1. So I am not understanding how this is returning the books or even why.

Sort your books in descending order, in-place below
books.sort!.reverse! { |firstBook, secondBook| firstBook <=> secondBook }


For an explanation of the spaceship operator try to read into the link


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.