Explorer
Node.js

Write a generator function `fibonacci()` that yields Fibonacci numbers indefinitely.

Problem Statement

Write a generator function `fibonacci()` that yields Fibonacci numbers indefinitely.

Complexity

Time Complexity: -

Space Complexity: -

Hints

šŸ’” Hint 1: Generator functions use function* and yield. šŸ’” Hint 2: Fibonacci: each number is the sum of the previous two. šŸ’” Hint 3: let a = 0, b = 1; while (true) { yield a; [a, b] = [b, a + b]; } āœ… Solution: ```javascript function* fibonacci() { let a = 0, b = 1; while (true) { yield a; [a, b] = [b, a + b]; } } ```

Generator Function

Medium
Write a generator function `fibonacci()` that yields Fibonacci numbers indefinitely.
Editor
Loading Editor...
Evaluate code
Output:Click "Run" above to execute and verify your code here.
[0,1,1,2,3,5,8,13]