I can't seem to figure this one out..
here is my code:

fruits.sort! { |firstfruit, secondfruit|
firstfruit <=> secondfruit }


Since we are using a block, we do not need to include end

fruits.sort! { |fruit1, fruit2| fruit2 <=> fruit1 }


thank you, super helpful!


is there any reason why we dont use end as we are using block


also can you help me.....i cant understand this program


Do you guys think there would be a problem using this way:

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

fruits.sort!.reverse! do |n|
n <=> n + 1

It works perfectly for me.


Is more code than necessary:

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


fruits.each { |x| puts "#{x}" }




I like your code much better. Definitely is simplified and makes perfect sense. Big fan. It won't pass me with that way though. Yours is probably much better and more efficient but they are saying they want the <=> symbol and won't give the green button until it's in there unfortunately. I'll remember your way for future stuff for sure. Thanks a bunch!


I wondered if this was a lesson requirement.


This will pass,

fruits.sort!.reverse! do |n|
#n <=> n + 1

and it works too. Why? Because reverse! did all the work. The do block has no effect. Consider the following...

fruits.sort! { |fruit1, fruit2| fruit2 <=> fruit1 }

Or we could stick to the do..end

fruits.sort! do | a, b | 
    b <=> a


Oh very interesting! And yep, that link you have posted is the exercise. I think it's getting a little more clear now. Well I'm definitely going back to this exercise and I'm gonna experiment with all this. Thanks a lot! That's a big help!