Skip to content

Instantly share code, notes, and snippets.

@UniBreakfast
Created October 3, 2021 08:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save UniBreakfast/5a3ff7f450622f4698298dd2c33edb36 to your computer and use it in GitHub Desktop.
Save UniBreakfast/5a3ff7f450622f4698298dd2c33edb36 to your computer and use it in GitHub Desktop.
Handmade iterable object applying iterator protocol
const bagOfRandom = {
[Symbol.iterator]: () => ({
next: () => {
if (Math.random() <= 0.01) return { done: true }
return { value: Math.floor(Math.random() * 100 + 1), done: false }
}
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment