transpose a 2D array (row-major to column-major, or vice versa)
the 2D array to be transposed
the transposed 2D array
const arr2d: Array2DRowMajor<T> = [ [1 , 2 , 3 , 4 , 5 ], [6 , 7 , 8 , 9 , 10], [11, 12, 13, 14, 15],]const arr2d_transposed: Array2DColMajor<number> = transposeArray2D(arr2d)arr2d_transposed === [ [1 , 6 , 11], [2 , 7 , 12], [3 , 8 , 13], [4 , 9 , 14], [5 , 10, 15],] Copy
const arr2d: Array2DRowMajor<T> = [ [1 , 2 , 3 , 4 , 5 ], [6 , 7 , 8 , 9 , 10], [11, 12, 13, 14, 15],]const arr2d_transposed: Array2DColMajor<number> = transposeArray2D(arr2d)arr2d_transposed === [ [1 , 6 , 11], [2 , 7 , 12], [3 , 8 , 13], [4 , 9 , 14], [5 , 10, 15],]
transpose a 2D array (row-major to column-major, or vice versa)
Param: arr2d
the 2D array to be transposed
Returns
the transposed 2D array
Example