3 ms·
In ruby, this is most easily achieved with: result = input.each_cons(3).map do |left, _, right| left + right end This maps over consecutive th
by p4lindromica 8y ago
In ruby, this is most easily achieved with:
result = input.each_cons(3).map do |left, _, right|
left + right
end
This maps over consecutive three-tuples in `input` and returns empty array for `len(input) < 3`.
Edit: nevermind, boundary conditions are still special cases.