Combining Generators
Explore how to combine multiple JavaScript generators using the yield* operator. Understand how to delegate iteration to other generators or iterable objects, enabling you to produce complex sequences like card suits and pips with concise and reusable code.
We'll cover the following...
We'll cover the following...
In the CardDeck class given in the below code widget, we have two generators:
- One to create the
suits - The other for
pips
It would be a shame if we have to duplicate the code to create a series that contains both suits and pips. Thankfully, we don’t have to endure such pain—JavaScript provides a way to combine generators.
Delegating to already created generator
Let’s create a method, suitsAndPips(), in the CardDeck class.
In the suitsAndPips() ...