Back to all solutions
#867 - Transpose Matrix
Problem Description
Given a matrix A, return the transpose of A.
The transpose of a matrix is the matrix flipped over it's main diagonal, switching the row and column indices of the matrix.
Solution
/**
* @param {number[][]} A
* @return {number[][]}
*/
var transpose = function(A) {
return A[0].map((_, i) => A.map(j => j[i]));
};