Cons of using reverse!


#1



Hi, I am wondering why for exercise 19 we are asked to use either <=> or else/elsif/else to compare and sort your fruits when reverse! would work better and be more concise.


fruits = ["orange", "apple", "banana", "pear", "grapes"]
fruits.sort!
fruits.reverse!

vs.

fruits = ["orange", "apple", "banana", "pear", "grapes"]
fruits.sort! do |firstfruit, secondfruit| secondfruit <=> firstfruit end


#2

It's not about which method is the best. It's what they tell you to do. They want you to practice using the <=> operators and the if/else if/else statements.

They didn't ask you "hey use the best concise method!"