Methods, Blocks and Sorting; 19. Sorting


#1

What am I doing wrong?
fruits = ["orange", "apple", "banana", "pear", "grapes"]
fruits.sort! { |banana, apple| banana <=> apple }
fruits.sort! { |grapes, orange| grapes <=> orange }

It gives me
Oops, try again. It looks like you didn't sort the fruits array in descending order. Did you remember to use .sort! instead of .sort ?


#2

It's because you didn't change the logical order
here is mine

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

fruits.sort! do |w,z|
    z <=> w
end

I f you do array.sort! { |y,x| y <=> x } is the same as you would write
array.sort! { |x,y| x <=> y } you have to change the order of the variables Like this!!!!
array.sort! { |x,y| y <=> x }


#3

Thank you soooo much!