This is my array
[{:amount=>10, :gl_acct_id=>1, :alt_amount=>20}, {:amount=>20, :gl_acct_id=>2 , :alt_amount=>30}]
i want result
[{:amount => 30}] or {:amount = 30}
Any idea?
Ruby versions >= 2.4.0 has an Enumerable#sum method. So you can do
arr.sum {|h| h[:amount] }
1.4m articles
1.4m replys
5 comments
57.0k users