I have an "array of arrays" that has two values included at a time.
array = [[:tuesday, 0.25], [:monday, 1], [:thursday, 0.75]]
I'd like to use the number in the "child" array to sort the "parent" array in descending order. The result would look like:
array = [[:monday, 1], [:thursday, 0.75], [:tuesday, 0.25]]
I'm not too sure where to begin here.
You can pass a block to the sort method like this:
array.sort { |a, b| b[1] <=> a[1] }
I would be inclined to write
array.sort_by(&:last).reverse
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With