14. The Combined Comparison Operator <=> understanding the logic



I got the code to pass through, but what I find difficult to comprehend is understanding why "book1" is GREATER than "book2"?

A Wrinkle in Time vs. A Brief History of Time

I understand it looks at the first character of the string, compares it, then moves to the next character. Having said that, shouldn't book2 be greater because "B" comes before "W"?


book_1 = "A Wrinkle in Time"

book_2 = "A Brief History of Time"

book_1 <=> book_2



Less than means, before and greater than means, after.

 > "a" < "b"
=> true
 > "b" > "a"
=> true

Which is correct. Wrinkle does follow Brief. In which case there is a swap.


gotcha! That was confusing for awhile, thanks for clarifying :slight_smile:


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