Create a function (e.g nFib) that takes a single integer parameter, n, and returns a list of the first n elements of the Fibonacci sequence.
Example in Javascript:
const nFib = (n) => {
// TODDO solution begins here
return [];
};
// nFib(1) => [ 0 ]
// nFib(2) => [ 0, 1 ]
// nFib(3) => [ 0, 1, 1 ]
// nFib(4) => [ 0, 1, 1, 2 ]
// nFib(5) => [ 0, 1, 1, 2, 3 ]
Example in Python:
def nFib(n):
# TODDO solution begins here
return [];
# nFib(1) => [ 0 ]
# nFib(2) => [ 0, 1 ]
# nFib(3) => [ 0, 1, 1 ]
# nFib(4) => [ 0, 1, 1, 2 ]
# nFib(5) => [ 0, 1, 1, 2, 3 ]