Why put 2 elements


#1



https://www.codecademy.com/en/courses/ruby-beginner-en-ET4bU/3/4?curriculum_id=5059f8619189a5000201fbcb


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 }


#2

@mannythegod
For an explanation of the spaceship operator try to read into the link
https://discuss.codecademy.com/t/19-how-does-actually-work/30726/11?u=leonhard.wettengmx.n


#3

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