Advertisement
Guest User

Untitled

a guest
Oct 16th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.41 KB | None | 0 0
  1. class IterableIterator {
  2. constructor(obj){
  3. this.index = 0
  4. this.data = Object.keys(obj).map((key) => { return { [key]: obj[key] } })
  5. }
  6. next = () => {
  7. if(this.index < this.data.length){
  8. return { value: this.data[this.index++], done: false }
  9. } else {
  10. this.index = 0
  11. return { value: undefined, done: true }
  12. }
  13. }
  14. [Symbol.iterator] = () => {
  15. return { next: this.next }
  16. }
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement