Skip to content

Instantly share code, notes, and snippets.

@bsdelf
Created September 22, 2020 03:54
Show Gist options
  • Save bsdelf/e30a54657f8e70f9a8e617f43434430c to your computer and use it in GitHub Desktop.
Save bsdelf/e30a54657f8e70f9a8e617f43434430c to your computer and use it in GitHub Desktop.
class Range {
constructor(from, to, step = 1) {
this.value = from;
this.to = to;
this.step = step;
}
next() {
if (this.value > this.to) {
return { value: undefined, done: true };
}
const value = this.value;
this.value = value + this.step;
return { value, done: false };
}
[Symbol.iterator]() {
return this;
}
}
for (const data of new Range(3, 4)) {
console.log(data);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment