Skip to content

Commit

Permalink
Merge pull request #24 from harsh6975/main
Browse files Browse the repository at this point in the history
added transpose of matrix
  • Loading branch information
suryapratapsinghsuryavanshi authored Oct 21, 2021
2 parents 22876c0 + bf6f4dc commit 65146c8
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/matrix/matrix.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 65146c8

Please sign in to comment.