Guest User

Untitled

a guest
Nov 17th, 2017
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.35 KB | None | 0 0
  1. function makeIterator(array) {
  2. let nextIndex = 0;
  3. return {
  4. next: function() {
  5. return nextIndex < array.length ?
  6. {value: array[nextIndex++], done: false} :
  7. {done: true};
  8. }
  9. };
  10. }
  11.  
  12. const it = makeIterator(['yo', 'lo']);
  13. console.log(it.next().value); // 'yo'
  14. console.log(it.next().value); // 'lo'
  15. console.log(it.next().done); // true
Add Comment
Please, Sign In to add comment