Open Tomotoes opened 4 years ago
🙃🙃🙃
const range = (start = 0, stop, step = 1) => { if (stop === undefined) { [start, stop] = [0, start] } start -= step return { [Symbol.iterator]: () => ({ next: () => ({ value: start += step, done: start >= stop }) }) } } Number.prototype.to = stop => range(this, stop); for (let num of (1).to(10)) { // ... } console.log([...(1).to(10)]) // [1, 2, 3, 4, 5, 6, 7, 8, 9]
thank u, [Symbol.iterator].next
🙃🙃🙃
thank u, [Symbol.iterator].next