Created
July 11, 2018 00:52
-
-
Save btg5679/91048cc658db67594b6fe2bca4c70ef1 to your computer and use it in GitHub Desktop.
Simple Iterator
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
function makeIterator(array) { | |
var nextIndex = 0; | |
console.log("nextIndex =>", nextIndex); | |
return { | |
next: function() { | |
return nextIndex < array.length | |
? { value: array[nextIndex++], done: false } | |
: { done: true }; | |
} | |
}; | |
} | |
var it = makeIterator(["simple", "iterator"]); | |
console.log(it.next()); // {value: 'simple, done: false} | |
console.log(it.next()); // {value: 'iterator, done: false} | |
console.log(it.next()); // {done: true} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This comment and the one above do not have the delimiting
'
i.e.'simple'