-
Notifications
You must be signed in to change notification settings - Fork 1
cycle
Subhajit Sahu edited this page Feb 3, 2021
·
28 revisions
Obtain values that cycle through an iterable.
function cycle(x, i, n)
// x: an iterable
// i: start index [0]
// n: number of values [-1 ⇒ Inf]
const xiterable = require('extra-iterable');
var x = [1, 2, 3];
[...xiterable.cycle(x, 0, 2)];
// → [1, 2]
[...xiterable.cycle(x, 0, 4)];
// → [1, 2, 3, 1]
[...xiterable.cycle(x, 1, 6)];
// → [2, 3, 1, 2, 3, 1]