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
destructuring assignment
similar objects:
ClosedRange - range of integers (the hard way)
*closedRange() - range of integers (generator: the easy way)
*list() - finite arithmetic sequence
Sequence - sequence of numbers.
used in the example of
*zip()
*interleave()
*sequence()
Last updated 2 years ago