How to group_by year in this type data in Ruby -
i want group year:
[{"_id"=>{"year"=>2013, "month"=>8}, "count"=>69605}, {"_id"=>{"year"=>2013, "month"=>7}, "count"=>60620}, {"_id"=>{"year"=>2013, "month"=>12}, "count"=>56026}, {"_id"=>{"year"=>2014, "month"=>5}, "count"=>55067}, {"_id"=>{"year"=>2014, "month"=>4}, "count"=>51313}, {"_id"=>{"year"=>2013, "month"=>11}, "count"=>48044}, {"_id"=>{"year"=>2014, "month"=>8}, "count"=>43802}, {"_id"=>{"year"=>2014, "month"=>1}, "count"=>40428}, {"_id"=>{"year"=>2014, "month"=>3}, "count"=>39564}, {"_id"=>{"year"=>2013, "month"=>9}, "count"=>35682}, {"_id"=>{"year"=>2013, "month"=>10}, "count"=>34073}, {"_id"=>{"year"=>2014, "month"=>2}, "count"=>32774}, {"_id"=>{"year"=>2014, "month"=>6}, "count"=>30772}, {"_id"=>{"year"=>2014, "month"=>9}, "count"=>17347}, {"_id"=>{"year"=>2014, "month"=>7}, "count"=>5319}, {"_id"=>{"year"=>2013, "month"=>6}, "count"=>4468}, {"_id"=>{"year"=>2013, "month"=>5}, "count"=>2978}, {"_id"=>{"year"=>2013, "month"=>4}, "count"=>2498}, {"_id"=>{"year"=>2013, "month"=>3}, "count"=>360}, {"_id"=>{"year"=>2013, "month"=>1}, "count"=>112}, {"_id"=>{"year"=>2012, "month"=>12}, "count"=>88}, {"_id"=>{"year"=>2013, "month"=>2}, "count"=>28}, {"_id"=>{"year"=>2015, "month"=>11}, "count"=>1}]
could me?
try this
your_array.group_by{|a| a["_id"]["year"]}
Comments
Post a Comment