-
-
Save Ocoldwell/6ef6498f58b2df9496886fcb5321f96b to your computer and use it in GitHub Desktop.
function fromTo that produces a generator, that will produce values in a range
This file contains 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
function fromTo(min, max) { | |
const gen = range(min, max); | |
return function generator() { | |
return gen.next().value; | |
} | |
} | |
function* range(min, max) { | |
for (let i = min; i <= max; i++) { | |
yield i; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment