✨ClosedRange
Last updated
Was this helpful?
Last updated
Was this helpful?
Was this helpful?
JS⟩ iteration ⟩ iterable ⟩ custom ⟩ ClosedRange
💾 replit:ClosedRange
👉 compare: *closedRange() (the easy way), *list()
// ⭐ closed range of integers
// (an iterable, which can make iterators)
class ClosedRange {
// init
constructor(start, end) {
this.start = start;
this.end = end;
}
💈範例:
// for-of loop
for (const i of closedRange(1, 3)) console.log(i); // 1 2 3
// spread into array elements
[...closedRange(1, 5)] // [ 1, 2, 3, 4, 5 ]