Last active
September 17, 2017 20:50
-
-
Save mickaelandrieu/25672eca6fa449c63e25ab3b84419532 to your computer and use it in GitHub Desktop.
ES6 array iterator using generator
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
/** | |
* let it = arrayIterator(['foo', 'bar', 'baz']); | |
* it.next().value; // "foo" | |
* it.next().value; // "bar" | |
* it.next().value; // "baz" | |
* it.next().value; // undefined | |
*/ | |
function* arrayIterator() { | |
let array = arguments; | |
let index = 0; | |
yield* array[index]; | |
index++; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment