What is the easiest way to convert
[x1, x2, x3, ... , xN]
to
[[x1, 2], [x2, 3], [x3, 4], ... , [xN, N+1]]
I have always enjoyed the syntax of this style:
a = [1, 2, 3, 4] a.each_with_index.map { |el, index| el + index } # => [1, 3, 5, 7]
Invoking each_with_index gets you an enumerator you can easily map over with your index available.
each_with_index