Answered by : successful-serval-yt6hyckpmdcb
function fibonacci(n) { if (n < 2){ return 1; }else{ return fibonacci(n-2) + fibonacci(n-1); }
}
console.log(fibonacci(7));
//Returns 21
Source : https://stackoverflow.com/questions/8845154/how-does-the-fibonacci-recursive-function-work | Last Update : Sat, 12 Jun 21
Answered by : aggressive-antelope-o8lg5jnm1oue
var fib = function(n) { if (n === 1) { return [0, 1]; } else { var arr = fib(n - 1); arr.push(arr[arr.length - 1] + arr[arr.length - 2]); return arr; }
};
console.log(fib(8));
Source : https://stackoverflow.com/questions/49341667/fibonacci-recursive-function-with-an-output-of-the-array-of-the-sequence-in-java | Last Update : Fri, 15 May 20
Answered by : aditya-pratap-singh-o2kiks565itt
// Time complexity O(2^n)
function fibonacci(num){ if(num < 2) return num; return fibonacci(num - 2) + fibonacci(num - 1)
}
console.log(fibonacci(2)) // 1
Source : | Last Update : Sat, 20 Aug 22
Answered by : aggressive-antelope-o8lg5jnm1oue
var fib = function(n) { if (n === 1) { return [0, 1]; } else { var arr = fib(n - 1); arr.push(arr[arr.length - 1] + arr[arr.length - 2]); return arr; }
};
console.log(fib(2));
Source : https://stackoverflow.com/questions/49341667/fibonacci-recursive-function-with-an-output-of-the-array-of-the-sequence-in-java | Last Update : Fri, 15 May 20
Answered by : anxious-aardvark-ulrmxmvtk661
function fib(n) { if (n < 2){ return n } return fib(n - 1) + fib (n - 2)
}
Source : https://medium.com/quick-code/fibonacci-sequence-javascript-interview-question-iterative-and-recursive-solutions-6a0346d24053 | Last Update : Wed, 17 Nov 21
Answered by : red-team
function fibonacci(n) { if (n < 2){ return 1; }else{ return fibonacci(n-2) + fibonacci(n-1); }
}
console.log(fibonacci(7));
Source : | Last Update : Wed, 23 Feb 22