Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- r = {
- "list": [
- {
- "id": "AAA",
- "total": "0.1"
- },
- {
- "id": "AAA",
- "total": "0.3"
- },
- {
- "id": "BBB",
- "total": "0.8"
- }
- ]
- }
- out = r.to_h[:list].group_by { |x| x[:id] }.map do |x|
- {
- symbol: x[0],
- total: x[1].sum { |i| i[:total].to_f }
- }
- end
- puts out
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement