I have
[
{:date => "2012-05", :post => 1},
{:date => "2012-12", :post => 1},
{:date => "2013-02", :post => 1},
{:date => "2012-05", :online => 1}
]
And I want to get:
[
{:date => "2012-05", :post => 1, :online => 1},
{:date => "2012-12", :post => 1 },
{:date => "2013-02", :post => 1 }
]
Anyone sees how to apply Ruby hash/array methods to achieve this?
q.group_by { |x| x[:date] }.values.map { |e| e.reduce :merge }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With