find the transpose of the matrix 3 2 1 5 4 3 a − −     = −       in javascript

index.tsx
function transposeMatrix(matrix) {
    return matrix[0].map((_, colIndex) => matrix.map(row => row[colIndex]));
}

// Example matrix
const matrix = [[3, 2, 1], [5, 4, 3], ["a", "-", "-"]];

const transpose = transposeMatrix(matrix);

console.log(transpose);
258 chars
11 lines

related categories

gistlibby LogSnag