Answers for "recursion fibbo in javascript"

1

js fibonacci sequence

var i;
    var fib = []; // Initialize array!

    fib[0] = 0;
    fib[1] = 1;
    for (i = 2; i <= 10; i++) {
      // Next fibonacci number = previous + one before previous
      // Translated to JavaScript:
      fib[i] = fib[i - 2] + fib[i - 1];
      console.log(fib[i]);
    }
Posted by: Guest on July-03-2020
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
-1

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

Code answers related to "recursion fibbo in javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language