How to make all the numbers in the Fibanacci sequence go in order, and not just the final result?
-
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 -
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 -
Calculate them in order in a loop, not recursively. Your K.O.Anonymous
2 Answers
Your Answer
To place the code, please use CodePen or similar tool. Thanks you!