function createCounters() {
const counters = [];
for (let i = 0; i < 3; i++) {
let count = 0;
counters.push(() => {
count += i;
return count;
});
}
return counters;
}
const counters = createCounters();
const first = counters.map(fn => fn()).join(',');
const second = counters.map(fn => fn()).join(',');
console.log(first, second); Post #3485
2.04K
CHALLENGE
- ❤ 2
- 🔥 1