Fibonacci Generator Lab
In this lab, you will create a generator function that returns a generator object which yields the Fibonacci sequence. The Fibonacci sequence is defined by the relation Xn = Xn-1 + Xn-2
. The first few numbers of the series are 0, 1, 1, 2, 3, 5, 8, 13.
Lab Requirements
- Use ESM import/export everywhere.
- Write a bug-free code.
- Pass all the challenges provided in the lab.
Examples
Example 1:
Input: callCount = 5 Output: [0, 1, 1, 2, 3] Explanation: const gen = fibGenerator(); gen.next().value; // 0 gen.next().value; // 1 gen.next().value; // 1 gen.next().value; // 2 gen.next().value; // 3
Example 2:
Input: callCount = 0 Output: [] Explanation: gen.next() is never called so nothing is outputted
Example 3:
Input: callCount = 10 Output: [0, 1, 1, 2, 3, 5, 8, 13, 21, 34] Explanation: const gen = fibGenerator(); gen.next().value; // 0 gen.next().value; // 1 gen.next().value; // 1 gen.next().value; // 2 gen.next().value; // 3 gen.next().value; // 5 gen.next().value; // 8 gen.next().value; // 13 gen.next().value; // 21 gen.next().value; // 34
Constraints:
- 0 <= callCount <= 50