Skip to content
Subhajit Sahu edited this page Feb 3, 2021 · 19 revisions

Rotates values in iterable. 🏃 📼 📦 🌔 📒

Similar: repeat, cycle, rotate, reverse.


iterable.rotate(x, [n]);
// x: an iterable
// n: rotate amount (+ve: left, -ve: right) (0)
const iterable = require("extra-iterable");

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

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

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


References

Clone this wiki locally