我有两个哈希:
first = { 1 => [15, 15, 15, 8], 4 => [11, 12, 7, 7], 5 => [14, 17, 13, 13],
6 => [19, 19, 15, 15], 7 => [5, 12, 12, 12], 8 => [10, 14, 14, 14],
9 => [8, 7, 8, 8] }
second = { 1 => [0, 1, 2], 4 => [2, 3], 5 => [2, 3], 6 => [0, 1, 2, 3],
7 => [1, 2, 3], 8 => [1, 2, 3], 9 => [2, 3] }
如您所见,它们都使用相同的键,但值不同。second
的值包含 的值的索引范围,first
我只需要对这些范围内的值求和first
。
预期输出:
result = { 1 => [45], 4 => [14], 5 => [26], etc }