Merging arrays into nested

arr1 = [10,20,30]
arr2 = [100,200,300]
arr3 = [40,50,60]

desired oupput will be like below
result = [[10,100,40],[20,200,50],[30,300,60]]
how can i achieve this?

Exactly as you wrote?


result = [arr1, arr2, arr3]

Now, if you want a “general solution”, that means how to nest n arrays?

Well, the n arrays are already a “collection” of arrays… it is already nested.

just iterate the arrays and use push/pop/unshift.
(solution assumes all arrays have equal size)

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs