0.0.3 • Published 7 years ago

rotate-matrix v0.0.3

Weekly downloads
7
License
MIT
Repository
github
Last release
7 years ago

rotate-matrix

Rotate a matrix in either direction.

Install

npm install rotate-matrix
bower install rotate-matrix

Usage

var rotateMatrix = require('rotate-matrix');

// 90° clockwise rotation (default)
console.log(rotateMatrix([
  [1,2,3],
  [4,5,6],
  [7,8,9]
]));

/*
[
  [7,4,1],
  [8,5,2],
  [9,6,3]
]
*/

// 180° clockwise rotation
console.log(rotateMatrix([
  [1,2,3],
  [4,5,6],
  [7,8,9]
], 2));

/*
[
  [9,8,7],
  [6,5,4],
  [3,2,1]
]
*/

// 270° clockwise rotation
console.log(rotateMatrix([
  [1,2,3],
  [4,5,6],
  [7,8,9]
], 3));

/*
[
  [3,6,9],
  [2,5,8],
  [1,4,7]
]
*/

// 360° clockwise rotation
console.log(rotateMatrix([
  [1,2,3],
  [4,5,6],
  [7,8,9]
], 4));

/*
[
  [1,2,3],
  [4,5,6],
  [7,8,9]
]
*/

// 90° counter-clockwise rotation
console.log(rotateMatrix([
  [1,2,3],
  [4,5,6],
  [7,8,9]
], -1));

/*
[
  [3,6,9],
  [2,5,8],
  [1,4,7]
]
*/

// 180° counter-clockwise rotation
console.log(rotateMatrix([
  [1,2,3],
  [4,5,6],
  [7,8,9]
], -2));

/*
[
  [9,8,7],
  [6,5,4],
  [3,2,1]
]
*/

Test

npm test

License

MIT

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

9 years ago