a = [{"user"=>"a1", "drink"=>"d1", "price"=>"60"},
{"user"=>"a2", "drink"=>"d2", "price"=>"30"},
{"user"=>"a3", "drink"=>"d3", "price"=>"30"},
{"user"=>"a2", "drink"=>"d4", "price"=>"40"}]
b = []
a.each_with_object({}) do |x|
count = b.find {|y| y["user"] == x["user"] }
if count.nil?
b << x
else
count["price"] = count["price"].to_i + x["price"].to_i
count["price"] = count["price"].to_s
end
end
puts b
1
solved I have a array of hash in which I have user name and price and I wants to retrieve uniq order [closed]