Created
March 2, 2018 07:37
-
-
Save vldvel/5d0c25eae0d69df5c351b11b98f8482e to your computer and use it in GitHub Desktop.
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 * generator(arr) { | |
for (const el in arr) | |
yield el; | |
} | |
const gen = generator([0, 1, 2]); | |
for (const g of gen) { | |
console.log(g); // 0 -> 1 -> 2 | |
} | |
gen.next(); // {value: undefined, done: true} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment