Skip to content

Instantly share code, notes, and snippets.

@wkronemeijer
Last active August 29, 2015 14:25
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 wkronemeijer/f1108fda71e70d670bf3 to your computer and use it in GitHub Desktop.
Save wkronemeijer/f1108fda71e70d670bf3 to your computer and use it in GitHub Desktop.
Python-like iterators for using .next() in a sequence
this.iter = function iter(array) {
var copy = array.slice();
var i = 0;
var max = copy.length - 1;
var next = function next() {
var index = i
i += 1
if (index > max) {
return undefined
} else {
return copy[index]
}
}
return {
next: next
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment