I have an array of hashes:
[{:foo => 1, :bar => 2}, {:foo => 2, :bar => 4} ...]
And an array of integers:
[3, 6]
I want combine the values from the integer array and the hashes to end up with something like:
[{:foo => 1, :bar => 2, :baz => 3}, {:foo => 2, :bar => 4, :baz => 6}]
I am currently doing this:
myArrayOfHashes.each_with_index |myHash, index|
myHash[:baz] = myArrayOfIntegers[index]
end
Is that the right approach?
I was imagining a more functional approach where I iterate over both arrays simultaneously, like something using zip
+ map
.