Skip to content

Instantly share code, notes, and snippets.

@leonardreidy
Last active September 27, 2019 13:51
Show Gist options
  • Save leonardreidy/042bad053a6ff16843bccb2e8b304171 to your computer and use it in GitHub Desktop.
Save leonardreidy/042bad053a6ff16843bccb2e8b304171 to your computer and use it in GitHub Desktop.
class IterableIterator {
constructor(obj){
this.index = 0
this.data = Object.keys(obj).map((key) => { return { [key]: obj[key] } })
}
next = () => {
if(this.index < this.data.length){
return { value: this.data[this.index++], done: false }
} else {
this.index = 0
return { value: undefined, done: true }
}
}
[Symbol.iterator] = () => {
return { next: this.next }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment