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

Gives values that cycle through an iterable. 🏃 📼 📦 🌔 📒

Similar: repeat, cycle, rotate, reverse.

iterable.cycle(x, [i], [n]);
// x: an iterable
// i: start index (0)
// n: number of values (-1 => Inf)
const iterable = require("extra-iterable");

var x = [1, 2, 3];
[...iterable.cycle(x, 0, 2)];
// [ 1, 2 ]

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

[...iterable.cycle(x, 1, 6)];
// [ 2, 3, 1, 2, 3, 1 ]

references

Clone this wiki locally