我有一个按年份分组的数组哈希,如下所示:
{
1979 => [
[0] {
:x => "12/79",
:y => 71,
:date => Sat, 01 Dec 1979
}
],
1980 => [
[0] {
:x => "01/80",
:y => 1680,
:date => Tue, 01 Jan 1980
},
[1] {
:x => "08/80",
:y => 1,
:date => Fri, 01 Aug 1980
}
]
}
我需要一种[:y]
按年份对所有键值求和的方法,然后将新值推送到另一个散列(或折叠相同的散列)中,我在其中设置:x
.
输出看起来像这样:
{
{
:x => "1/79",
:y => 71,
},
{
:x => "1/1980",
:y => 1681
}
}