Intermediate Algorithm Scripting: Sum All Odd Fibonacci Numbers

Intermediate Algorithm Scripting: Sum All Odd Fibonacci Numbers
0

#1

Hi!

I am getting these two different outputs from the same code depending on which tools I am using whether fcc or chrome.

Can anyone teach me why and what to learn from this ?


#2

in FCC the code may trigger an infinite loop point that prevents it from completing.
If you search the forum you will find how others have handled this.


#3

In general if FCC appears to be missing a significant part of a loop’s result, it is likely that the function is taking too long and getting cut short

Something in particular that’s hurting your performance:

In that recursive form it’s very slow and keeps recalculating results it had previously computed

You can solve this in two straightforward ways:

  1. Give up on the recursive solution, and go iterative with a loop
  2. Memoize the fib function (store results in an object/array and check if the result is there)

Doesn’t really matter which