I need to write a function using recursion without using an array at the same time. Which will return all the values of the Fibonacci digits to n
. n > 0
;
function fib(number) {
if (number === 1) {
return "0,1,1";
}
if (number === 2) {
return "0,1,1,2,";
} else {
let fibList = fib(number - 1);
return (fibList += `${number - 2 + number - 1},`);
}
}
console.log(fib(45));
My code doesn’t work as I want, I don’t know how to fix it.
n=7 “0, 1, 1, 2, 3, 5 “
n=45 “0, 1, 1, 2, 3, 5, 8, 13, 21, 34”