DE
Size: a a a
DE
AK
AK
DE
DE
AK
DE
AK
DE
AK
DE
p
function cycleIterator (arr) {
let count = 0;
return function inner () {
if(count > arr.length - 1) {
count = 0;
}
count += 1;
return arr[count - 1];
}
}
const threeDayWeekend = ['Fri', 'Sat', 'Sun'];
const getDay = cycleIterator(threeDayWeekend);
console.log(getDay()); // should log: 'Fri'
console.log(getDay()); // should log: 'Sat'
console.log(getDay()); // should log: 'Sun'
console.log(getDay()); // should log: 'Fri'
S
function cycleIterator (arr) {
let count = 0;
return function inner () {
if(count > arr.length - 1) {
count = 0;
}
count += 1;
return arr[count - 1];
}
}
const threeDayWeekend = ['Fri', 'Sat', 'Sun'];
const getDay = cycleIterator(threeDayWeekend);
console.log(getDay()); // should log: 'Fri'
console.log(getDay()); // should log: 'Sat'
console.log(getDay()); // should log: 'Sun'
console.log(getDay()); // should log: 'Fri'
p
L
const cycleIterator = (arr, i = 0) => () => arr[i++ % arr.length]
DE
const cycleIterator = (arr, i = 0) => () => arr[i++ % arr.length]
L
p
const cycleIterator = (arr, i = 0) => () => arr[i++ % arr.length]
L
function* cycleIterator(a) {
while(1)
for(const v of a)
yield v
}
const sleep = m => new Promise(r => setTimeout(r, m))
for(const v of cycleIterator([1,2,3])) {
console.log({ v })
await sleep(1e3)
}
S
function* cycleIterator(a) {
while(1)
for(const v of a)
yield v
}
const sleep = m => new Promise(r => setTimeout(r, m))
for(const v of cycleIterator([1,2,3])) {
console.log({ v })
await sleep(1e3)
}