Skip to content

@goatslacker /step-through
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
var arr = [1, "2", null, 4, undefined, 6, 7, 8];
var j = {
step: function (arr) {
var current = -1;
var len = arr.length;
var err = new Error("End of list");
return {
current: function () {
if (current < 0 || current >= len) {
throw err;
} else {
return arr[current];
}
},
next: function () {
current += 1;
return this.current();
},
previous: function () {
current -= 1;
return this.current();
}
}
}
};
var iter = j.step(arr);
console.log(iter.next());
console.log(iter.next());
console.log(iter.next());
console.log(iter.next());
console.log(iter.next());
console.log(iter.next());
console.log(iter.next());
console.log(iter.next());
console.log(iter.next());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.