Iterables and generators

What array does [...generator()] produce?

Examples

Worked example

Input
A generator yields 4 and then 7.
Expected output
[4, 7]

Hints and solution

Hint 1

Write down the starting state and walk through one example by hand.

Reveal worked answer

The spread operation repeatedly asks for the next value until the generator finishes.

Back to the lesson