Answers for "fibonacci series in javascript recursion"

1

fibonacci recursion javascript

function fibonacci(n) {
    if (n < 2){
        return 1;
    }else{
        return fibonacci(n-2) + fibonacci(n-1);
    }
}

console.log(fibonacci(7));
//Returns 21
Posted by: Guest on June-05-2021
0

recursive function for fibonacci series in java javascript

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));
Posted by: Guest on May-08-2020

Code answers related to "fibonacci series in javascript recursion"

Code answers related to "Javascript"

Browse Popular Code Answers by Language