What is the easiest way to convert a ruby array to an array of consecutive pairs of its elements?
I mean: x = [a, b, c, d]
→ y = [[a, b], [c, d]]
What is the easiest way to convert a ruby array to an array of consecutive pairs of its elements?
I mean: x = [a, b, c, d]
→ y = [[a, b], [c, d]]
y = x.each_slice(2).to_a
irb(main):001:0> [0,1,2,3,4,5].each_slice(2).to_a
=> [[0, 1], [2, 3], [4, 5]]