Answers for "fibonacci algorithm generator"

2

fibonacci generator

function fibonacciGenerator(n) {

  var output = [];
  if (n === 1) {
    output = [0];
  } else if (n === 2) {
    output = [0, 1];
  } else {
    output = [0, 1];
    for (var i = 2; i < n; i++) {
      output.push(output[output.length - 2] + output[output.length - 1]);
    }

  }
  return output;
}
output = fibonacciGenerator(50);
console.log(output);
Posted by: Guest on February-27-2021

Code answers related to "fibonacci algorithm generator"

Browse Popular Code Answers by Language