transpose-matrix

1.2.0 • Public • Published

Transpose a matrix

Pass a matrix in and get a transposed matrix out

const testMatrixSquare = [
  [1,2,3,4,5,6,7,8,9],
  [1,2,3,4,5,6,7,8,9],
  [1,2,3,4,5,6,7,8,9],
  [1,2,3,4,5,6,7,8,9],
  [1,2,3,4,5,6,7,8,9],
  [1,2,3,4,5,6,7,8,9],
  [1,2,3,4,5,6,7,8,9],
  [1,2,3,4,5,6,7,8,9],
  [1,2,3,4,5,6,7,8,9]
];

transposeMatrix(testMatrixSquare)';

Will return

    const expectedResults = [
      [1,1,1,1,1,1,1,1,1],
      [2,2,2,2,2,2,2,2,2],
      [3,3,3,3,3,3,3,3,3],
      [4,4,4,4,4,4,4,4,4],
      [5,5,5,5,5,5,5,5,5],
      [6,6,6,6,6,6,6,6,6],
      [7,7,7,7,7,7,7,7,7],
      [8,8,8,8,8,8,8,8,8],
      [9,9,9,9,9,9,9,9,9]
    ];
   

See the test cases for other usages.

Package Sidebar

Install

npm i transpose-matrix

Weekly Downloads

2

Version

1.2.0

License

ISC

Last publish

Collaborators

  • jaydaro