开发者

Recreate array so that array[x][y] become newarray[y][x]

开发者 https://www.devze.com 2022-12-09 02:37 出处:网络
Is there a standard method to create a new array from a two dimensional array so that array[x][y] would be accessed as [y][x] on the new array?

Is there a standard method to create a new array from a two dimensional array so that array[x][y] would be accessed as [y][x] on the new array?

For example, from:

[ [00,01,02,03,04,开发者_JS百科05],
  [10,11,12,13,14,15],
  [20,21,22,23,24,25] ]

Would become:

[ [00,10,20],
  [01,11,21],
  [02,12,22],
  [03,13,23],
  [04,14,24],
  [05,15,25] ]


I believe you are looking for Array#transpose

0

精彩评论

暂无评论...
验证码 换一张
取 消