Answer the question
In order to leave comments, you need to log in
How in Ruby, having such a hash, sort by condition?
For example, there is a hash like this:
list { :plan => {1000, 3000, 100}, :present => {530, 700,85 }}
list { :plan => {100, 1000, 3000}, :present => {85, 530, 700 }}
Answer the question
In order to leave comments, you need to log in
In your every question, the logic of hashes was initially laid down, which is why you suffer.
arr = [ { plan: 1000, present: 530 }, { plan: 3000, present: 700 }, { plan: 100, present: 85 } ]
arr.sort_by {|v| v[:plan] - v[:present] }
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question