JSFiddle - React, Tailwind, and code Playground
by d131
JavaScript
const test = ["one", "two", "three", "four"];
function* singleRunGenerator(i) {
while (i < test.length) {
yield test[i];
i++;
}
}
function* repeatingGenerator(i) {
while (i <= test.length) {
yield test[i];
if (i < test.length) {
i++;
} else {
i = 0;
}
}
}
let gen = singleRunGenerator(0);
console.log(gen.next().value);
console.log(gen.next().value);
console.log(gen.next().value);
console.log(gen.next().value);
console.log(gen.next().done);
console.log(gen.next().value);