class RangeIterator {
constructor(start, stop) {
this.value = start;
this.stop = stop;
}
[Symbol.iterator]() { return this; }
next() {
var value = this.value;
if (value < this.stop) {
this.value++;
return {done: false, value: value};
} else {
return {done: true, value: undefined};
}
}
}
// with generators
function* range(start, stop) {
for (var i = start; i < stop; i++)
yield i;
}
Created
May 30, 2017 09:38
-
-
Save tomcask/a59353f592b239a6e6a237099e355518 to your computer and use it in GitHub Desktop.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment