diff --git a/src/matrix/matrix.js b/src/matrix/matrix.js index 3903a7b..6bdbabf 100644 --- a/src/matrix/matrix.js +++ b/src/matrix/matrix.js @@ -70,8 +70,29 @@ let matSpiralPrint = (mat1) => { return str; } +// transpose of matrix +let matTrans = (mat) => { + // make another same dimension matrix + let resultMat = new Array(); + + for(let j = 0; j < mat[0].length; j++){ + // create a row for new transpose matrix. + let row = new Array(); + for(let i = 0; i < mat.length; i++){ + // push the column value into row. + row.push(mat[i][j]); + } + // push the row value for the result matrix. + resultMat.push(row); + } + // return result matrix. + return resultMat; +} + + module.exports = { matAdd, matSub, - matSpiralPrint + matSpiralPrint, + matTrans } \ No newline at end of file