Last active
April 26, 2017 04:57
-
-
Save devmobasa/7f81dc14eea77d3d2b02aba114aed862 to your computer and use it in GitHub Desktop.
JavaScript Iterators - Coding Blast - www.codingblast.com
This file contains hidden or 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) { | |
| let index = 0; | |
| return { | |
| next: function () { | |
| if (index < array.length) { | |
| return { value: array[index++], done: false }; | |
| } else { | |
| return { done: true }; | |
| } | |
| } | |
| }; | |
| } | |
| let it = makeIterator(['coding', 'blast']); | |
| console.log(it.next()); // [object Object] { done: false, value: "coding" } | |
| console.log(it.next()); // [object Object] { done: false, value: "blast" } | |
| console.log(it.next()); // [object Object] { done: true } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment