Skip to content

Instantly share code, notes, and snippets.

@yefremov
Last active February 20, 2017 16:40
Show Gist options
  • Save yefremov/2ca3ebbfe30dafbf00254ba5a94e8ddd to your computer and use it in GitHub Desktop.
Save yefremov/2ca3ebbfe30dafbf00254ba5a94e8ddd to your computer and use it in GitHub Desktop.

Revisions

  1. yefremov revised this gist Feb 20, 2017. No changes.
  2. yefremov created this gist Feb 20, 2017.
    16 changes: 16 additions & 0 deletions iterator.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@

    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 };
    };
    }