我想借此陣列哈希值的數組...合併和鞏固哈希
items => [{:name=>"item a", :count=>1, :contributors=>["51db6d58bd02861e96000004"]},
{:name=>"item b", :count=>1, :contributors=>["51db6d58bd02861e96000004"]},
{:name=>"item a", :count=>1, :contributors=>["51db6d58bd02861e96000004"]},
{:name=>"item b", :count=>1, :contributors=>["51db6d58bd02861e96000004"]},
{:name=>"item c", :count=>1, :contributors=>["51db6d58bd02861e96000004"]},
{:name=>"item d", :count=>1, :contributors=>["51db6d58bd02861e96000004"]}]
,並得到一個輸出,看起來像以下...
items => [{:name=>"item a", :count=>2, :contributors=>["51db6d58bd02861e96000004", "51db6d58bd02861e96000004"]},
{:name=>"item b", :count=>2, :contributors=>["51db6d58bd02861e96000004, 51db6d58bd02861e96000004"]},
{:name=>"item c", :count=>1, :contributors=>["51db6d58bd02861e96000004"]},
{:name=>"item d", :count=>1, :contributors=>["51db6d58bd02861e96000004"]}]
我想要按名稱分組並統計計數,並按照上面的說明進行貢獻。我怎麼做? Group_by,減少?有人可以發表一個例子嗎?
請顯示您到目前爲止嘗試了些什麼。 – 2014-09-27 03:20:26
什麼是'items =>'?這部分使你的表達無效。 – sawa 2014-09-27 03:24:06
你的意思是'物品= [...]'? – falsetru 2014-09-27 03:26:46