💾*integers()
infinite sequence: 0, 1, 2, 3, ...
JS⟩ iteration ⟩ custom generators ⟩ *integers()
💾 replit:integers()
🌀 extension: Iterator - extend built-in iterable iterators.
// ⭐️ infinite sequence: 0, 1, 2 ...
function* integers() {
let i = 0;
while (true) { yield i++ }
}
💈範例:
// ⭐️ iterable destructuring
const [a, b, c] = integers();
console.log(a, b, c); // 0, 1, 2
similar objects:
*list() - finite arithmetic sequence