Problem 25
First n Fibonacci Recursion Challenge
Given a positive integer n, return an array containing the first n Fibonacci numbers. The Fibonacci sequence starts with 0 and 1, and each subsequent number is the sum of the two before it. The starting 0 is always included in the output but does not count toward n.
Function Signature
fibonacci(n)
Parameters
n— an integer. If zero or negative, returnnull.
Output
Return an array of Fibonacci numbers, or null if n is zero or negative.
Constraints
- The function must use recursion.
- The function should accept exactly one argument.
Examples
fibonacci(1) → [0, 1]
fibonacci(2) → [0, 1, 1]
fibonacci(3) → [0, 1, 1, 2]
fibonacci(5) → [0, 1, 1, 2, 3, 5]
fibonacci(8) → [0, 1, 1, 2, 3, 5, 8, 13, 21]
fibonacci(0) → null
fibonacci(-7) → null