Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function makeIterator(array) {
- let nextIndex = 0;
- return {
- next: function() {
- return nextIndex < array.length ?
- {value: array[nextIndex++], done: false} :
- {done: true};
- }
- };
- }
- const it = makeIterator(['yo', 'lo']);
- console.log(it.next().value); // 'yo'
- console.log(it.next().value); // 'lo'
- console.log(it.next().done); // true
Add Comment
Please, Sign In to add comment