Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

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));
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #recursive #function #fibonacci #series #java #javascript
ADD COMMENT
Topic
Name
5+8 =