How to make all the numbers in the Fibanacci sequence go in order, and not just the final result?

  • 0
    let fib = (num) = & gt; {
    return num & lt; = 1
    ? num
    : fib (num - 1) + fib (num - 2);
    }
    console.log (fib (10));

    How to make all the numbers in the Fibanacci sequence go in order, and not just the final result?
    JavaScript Andrew Booker, Jan 21, 2019

  • 2 Answers
  • 0
    Make another output function in which to call your function. That is, something like this:

    let fib = (num) => {
    return num <= 1 ? num : fib(num - 1) + fib(num - 2);
    }

    let fibPrint = (num) => {
    var temp = '';
    for (var i=0; i<=num; i++){
    temp += fib(i);
    }
    console.log(temp);
    }

    fibPrint(10);
    Anonymous

  • 0
    Calculate them in order in a loop, not recursively. Your K.O.
    Anonymous

Your Answer
To place the code, please use CodePen or similar tool. Thanks you!