Skip to content

Instantly share code, notes, and snippets.

@yefremov
Last active February 20, 2017 16:40
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 yefremov/2ca3ebbfe30dafbf00254ba5a94e8ddd to your computer and use it in GitHub Desktop.
Save yefremov/2ca3ebbfe30dafbf00254ba5a94e8ddd to your computer and use it in GitHub Desktop.
Two versions of a collection iterator factory
function iterate(iterable) {
var index = -1;
return function next() {
return ++index < iterable.length ? iterable[index] : null;
}
};
function makeIterator(iterable) {
var index = -1;
return function next() {
return ++index < iterable.length
? { value: iterable[index], key: index, next: next, done: false }
: { done: true };
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment