My code works and I have no idea why


#1



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


So, I actually solved this exercise by changing the position of the books to "secondBook <=> firstBook". However, looking at the "Hint" section I noted that this "<=>" is equivalent to that "IF" block. My issue is that, even if I changed the placeholders the logic for an IF is still the same, unless, when I changed the placeholders it also changed the comparison operators.


Replace this line with your code.


#2

The order of the expression operands determines the sort order. If they are the same as the block parameters, the sort order is ascending. If they are opposite, the sort order is descending. The background process utilizes an algo similar to that in the hint to judge how the operands relate to each other, but not the sort order. That is determined by our block.


#3

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