Skip to content
Subhajit Sahu edited this page May 3, 2023 · 23 revisions

Rotate values in array.

Alternatives: rotate, rotate$.
Similar: repeat, cycle, rotate, reverse.


function rotate(x, n)
// x: an array
// n: rotate amount ( ve: left, -ve: right) [0]
const xarray = require('extra-array');

var x = [1, 2, 3, 4];
xarray.rotate(x, 1);
// → [ 2, 3, 4, 1 ]

xarray.rotate(x, 2);
// → [ 3, 4, 1, 2 ]

xarray.rotate(x, -1);
// → [ 4, 1, 2, 3 ]


References

Clone this wiki locally