Last active
August 29, 2015 14:25
-
-
Save wkronemeijer/f1108fda71e70d670bf3 to your computer and use it in GitHub Desktop.
Python-like iterators for using .next() in a sequence
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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