I have an array:
arr=[[1,2,3],[4,5],[6]],
I have the following code:
arr.transpose
but it doesn't work,how to solve it?
I am getting
[[1,2,3],[4,5],[6]].transpose
IndexError: element size differs (2 should be 3)
from (irb):13:in `transpose'
from (irb):13
from /home/durrant
my solution:
arr.reduce(&:zip).map(&:flatten)
output:
[[1, 4, 6], [2, 5, nil], [3, nil, nil]]