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

Obtain values that cycle through array.

Similar: repeat, cycle, rotate, reverse.


function cycle(x, i, n)
// x: an array
// i: begin index [0]
// n: number of values [|x|]
const xarray = require('extra-array');

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

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

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


References

Clone this wiki locally