JS Built-ins
TypeScriptadvanced

Advanced β€” transpose<T>

πŸ“– Usage Example
transpose([[1, 2], [3, 4], [5, 6]])   // β†’ [[1, 3, 5], [2, 4, 6]]

transpose flips a matrix over its diagonal, converting rows to columns and vice versa.

Advanced: Matrix Transpose

Challenge: Implement transpose<T>(matrix: T[][]): T[][] rotating a 2D matrix 90Β° by swapping rows and columns.

transpose([[1,2,3],[4,5,6]])  // β†’ [[1,4],[2,5],[3,6]]
πŸ’‘ Hints (1)
  • β€’ Map over the columns index of the first row, then map each row to that column.