Generators and Iterators Quiz
Practice the iterator protocol from both sides: write an infinite Fibonacci generator, an async iterable, a `[Symbol.iterator]` implementation, and a `for...of` consumer.
Question Bank
Hard
JavaScript
quiz
generators
iterators
js-language
244 views
3
Implement an infinite Fibonacci generator fibonacci() using function* and consume the first 7 values with a for...of plus a counter.
Examples
Example 1:
Input: const it = fibonacci(); [...].first(7)
Output: 0, 1, 1, 2, 3, 5, 8
Explanation: `yield` pauses execution and returns a value; destructuring `[a, b] = [b, a + b]` advances both.3 more questions, with full solutions and explanations, are available for premium members.
Upgrade to Premium