I'm attempting to use Kendo UI to implement the Fibonacci sequence, however, I'm having speed difficulties while computing higher Fibonacci numbers. Here's an illustration of my code:
I'm using a recursive function in this code to compute the Fibonacci sequence up to the tenth number and save the results in an array. When I try to calculate greater Fibonacci numbers, however, the performance of my code suffers. For example, if I update the loop to compute the first 50 Fibonacci numbers, the code runs slowly.
I saw an article that suggested using an iterative method rather than a recursive approach. Is it going to work? Could someone please assist me?
function fibonacci(num) { if (num <= 1) { return 1; } return fibonacci(num - 1) + fibonacci(num - 2); } var series = []; for (var i = 0; i < 10; i++) { series.push(fibonacci(i)); } console.log(series);
I saw an article that suggested using an iterative method rather than a recursive approach. Is it going to work? Could someone please assist me?