Skip to content

Instantly share code, notes, and snippets.

@Ocoldwell
Last active September 6, 2022 18:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ocoldwell/6ef6498f58b2df9496886fcb5321f96b to your computer and use it in GitHub Desktop.
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
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