I am trying to write a loop that takes in a nested array and makes a sub-array of two consecutive tuples at a time. The input array may be something like this
arr = [['A','B'],['C','D'],['E','F'],['G','H'],['I','J'],['K','L'],
['M','N'],['O','P']]
Output: ['A','B'],['C','D']
['E','F'],['G','H']
['I','J'],['K','L']
['M','N'],['O','P']
I have tried out various loops, like
arr.each_slice(2) do |k,m|
new_arr=[k,m]
puts new_arr
end
and
arr.each_slice(2) { |k,m| puts(k,m) }
What is wrong with this? In both the cases, the output is
A
B
C
D .....