UNPKG

enhancedmath

Version:

This package contains some enhanced mathematical operations

13 lines (12 loc) 466 B
import { fillEmptyRows, getHighestRowLength } from '../Helpers'; /** * Returns the transposed matrix * @param {Array<any[]>} matrix A 2d array * @returns {Array<any[]>} The transposed matrix */ const transpose = (matrix) => { const rowLength = getHighestRowLength(matrix); const filledMatrix = fillEmptyRows(matrix, rowLength, null); return filledMatrix[0].map((_, colIndex) => filledMatrix.map((row) => row[colIndex])); }; export default transpose;