Sorting in descending order query (15 and 19)


I'm a little confused about the descending order sorting. As far as I understand, you can switch the terms on either side of the <=> or use an if/elsif/else combination. I was wondering however, why this isn't used (taken from part 19):

fruits = ["orange", "apple", "banana", "pear", "grapes"]


This seemed to work in terms of reversing the order in the display, so I was wondering if there's a reason that the other two methods are preferred, or if it's wrong to use reverse!?

Thank you!


We are learning basics, here. Optimizing code comes later and is not really covered in these courses. It's important to learn and understand the various mechanisms that are present in the language so we can recognize them and know how they work. This understanding is critical when it comes to refactoring our code to improve efficiency and readability.

Bottom line, whatever is covered in the lesson is what we need to stick with. No point looking for reasons why one thing is done and another (possibly better) thing is not.


Okay, thank you! I must have over-thought it - I'll stick to the other two methods then.