rotate-array
Installation
yarn add @bgoodman/rotate-array
Usage
Import package
import rotateArray from "@bgoodman/rotate-array";
Run tests
yarn test
API
rotateArray
Rotate a 1D or 2D array by n steps. Use n < 0
for left rotations and n > 0
for right rotations.
Throws error if attempting to rotate a jagged array.
rotateArray: <T>(array: Array<T> | Array<Array<T>>, steps: number) => Array<T> | Array<Array<T>>
Example
rotateArray([1,2,3,4], 1)
rotateArray([1,2,3,4], -1)
rotateArray([[1,2,3],[4,5,6],[7,8,9],[10,11,12]], 1)
rotateArray([[1,2,3],[4,5,6],[7,8,9],[10,11,12]], -1)