I have an array of arrays indicating coordinate values, like so:
cells = [ [0,0], [0,1] ]
Each array in the array is an X and Y value. So, if I want to shift this right, that would be X+1 on each cell. I could express this as a cell like so:
delta = [1,0]
Now, what I'd like to do is merge that value into each cell so that the X value of each cell is summed with the value of delta, so in this case the final output should be:
new_cells = [ [1,0], [1,1] ]
Here's the best I've been able to think of so far, it seems really heavy:
cells = [[0,0],[0,1]]
delta = [1,0]
cells.each do |cell|
cell[0] = cell[0] + delta[0]
cell[1] = cell[1] + delta[1]
end
# Now cells = [[1,0],[1,1]]
Is there a cleaner one-liner kind of method that would sum an array onto each array in a chain of arrays, or is the above the best solution to that problem?