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

Repeat an iterable given times.

Similar: repeat, cycle, rotate, reverse.


function repeat(x, n)
// x: an iterable
// n: times [-1 ⇒ Inf]
const xiterable = require('extra-iterable');

var x = [1, 2];
[...xiterable.repeat(x, 2)];
// → [1, 2, 1, 2]

[...xiterable.repeat(x, 3)];
// → [1, 2, 1, 2, 1, 2]


References

Clone this wiki locally