Created
October 3, 2021 08:41
-
-
Save UniBreakfast/5a3ff7f450622f4698298dd2c33edb36 to your computer and use it in GitHub Desktop.
Handmade iterable object applying iterator protocol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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