matrix-rotate
Version:
Rotate a 2D matrix by 90 degrees clockwise with one command
29 lines (22 loc) • 514 B
JavaScript
var rotator = require('../lib/rotateMatrix.js'),
assert = require('assert'),
givenMatrix,
correctRotated,
moduleOutput;
givenMatrix = [
[],
[],
[],
[]
];
correctRotated = [
[ 13, 9, 5, 1 ],
[ 14, 10, 6, 2 ],
[ 15, 11, 7, 3 ],
[ 16, 12, 8, 4 ]
];
runTest(givenMatrix, correctRotated, 'Simple 4x4 array');
function runTest(givenMatrix, correctRotated, msg) {
moduleOutput = rotator(givenMatrix);
assert.deepEqual(moduleOutput, correctRotated, msg);
}