Problem 26
Return nth Fibonacci Recursion Challenge
Given a non-negative integer n, return the Fibonacci number at that index. The Fibonacci sequence is [0, 1, 1, 2, 3, 5, 8, 13, 21, ...] where index 0 is 0 and index 1 is 1. If n is negative, return null.
Function Signature
nthFibo(n)
Parameters
n— an integer representing the index in the Fibonacci sequence.
Output
Return a number representing the Fibonacci value at index n, or null if n is negative.
Constraints
- The function must use recursion.
- The function should accept exactly one argument.
Examples
nthFibo(0) → 0
nthFibo(1) → 1
nthFibo(2) → 1
nthFibo(3) → 2
nthFibo(5) → 5
nthFibo(8) → 21
nthFibo(-5) → null