How to convert n arrays of length m to m arrays of length n?

I am trying to convert this:

[ [1, 2, 3, 4],
  [5, 6, 7, 8],
  [9, 10, 11, 12] ]

in it:

[ [1, 5, 9],
  [2, 6, 10],
  [3, 7, 11],
  [4, 8, 12] ]

Is there a built-in function for this? If this is not so, then what is shorter and cleaner?

+3
source share
1 answer

The built-in method you're looking for is Array # transpose

+9
source

Source: https://habr.com/ru/post/1758108/


All Articles