Hi I was trying to come up with a function to return a fibonacci sequence, that is an array not the usual last n-th fibonacci number.
function fib(n,arr=[0]) {
if (n===0||n===1) {
arr.push(n)
return arr;
}
let arr2 = fib(n-2);
let arr1 = fib(n-1);
arr1.push(arr2[arr2.length-1]+arr1[arr1.length-1]);
return arr1;
}
it works fine but I am not happy with the hard coded arr=[0] here. I tried to put arr=[] instead but the sequence I ended up getting excluded the first 0 entries in the array which should've been there.
I am sure there's better approaches to solve this.
P.S: I want to solve this using a recursive approach and I know it has a poor exponential time complexity but I just wanted to pratice my recursive programming skills.