Cool and concise Array operations
Merge array of hashes into one hash
a = [{a: 1, b: 2,c: 3},{b: 4, d: 1},{b: 3,c: 1}]
a.reduce(&:merge)
=> {:a=>1, :b=>3, :c=>1, :d=>1}
Remove empty hashes from array
a = [{},{a: 1},{},{}]
a.reject(&:empty?)
=> [{:a=>1}]
Written by Jeroen Rosenberg
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Ruby
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#