Sum All Odd Fibonacci Numbers helpp

Sum All Odd Fibonacci Numbers helpp
0

#1
function sumFibs(num) {
  
  var fibonacci = [1, 1];
  for (var i = 1; i < num; i++) {
      var answer = fibonacci[i] + fibonacci[i - 1];
      fibonacci.push(answer);

    }
  
  return fibonacci;
}

sumFibs(5);

Above is my code I am using to understand the problem. It is an incomplete solution. The problem I am having is that the code is crashing FCC challenge. I ran the code on Codepen.io with no issues. What am I missing?


#2

Your current solution is pushing 3,999,999 elements into an array which is resource intensive. You only need to push the Fibonacci numbers which are less than or equal to the num argument then you can sum the odd Fibonacci numbers which are in the fibonacci array.


#3

Hey Randell,

Thank you for the reply.

I managed to solve the problem by clearing the ‘auto execution’ of my code when loading the page. This is no longer an issue as I have since solved the problem.

Thanks again and sorry for the delay in getting back to you