I have a method:
def deltas_to_board_locations(deltas, x, y)
board_coords = []
deltas.each_slice(2) do |slice|
board_coords << x + slice[0]
board_coords << y + slice[1]
end
board_coords
end
where deltas is an array, and x,y are fixnums.
Is there a way to eliminate the first and last line to make the method more elegant?
Like:
def deltas_to_board_locations(deltas, x, y)
deltas.each_slice(2) do |slice|
board_coords << x + slice[0]
board_coords << y + slice[1]
end
end
deltas.each_slice(2).flat_map do |dx, dy|
[x + dx, y + dy]
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With