Created
January 27, 2019 09:43
-
-
Save hk-skit/602b01f794486bb02844364e57c2b642 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class RangeGenerator { | |
constructor({ | |
start = 0, | |
end = 1000, | |
step = 1 | |
}) { | |
this.start = start; | |
this.end = end; | |
this.step = step; | |
} | |
*[Symbol.iterator]() { | |
let start = this.start; | |
while (start <= this.end) { | |
yield start; | |
start += this.step; | |
} | |
} | |
} | |
const range = new RangeGenerator({ | |
start: 0, | |
end: 20, | |
step: 5 | |
}); | |
console.log(...range); // 0 5 10 15 20 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment