Sum of odd Fibonacci numbers

Sum of odd Fibonacci numbers
0.0 0

#1

For input values 75024 and 75025, outputs given are different. But the greatest fibonacci number less than 75025 and 75024 is same (46368). So, I don’t think the sum would change.

Here’s my code:

function sumFibs(num) {
  var fib = [];
  fib[0] = 0;
  fib[1] = 1;
  var sum = 1;
  var i = 2;
  while(fib[i-1]<num)
    {
      fib[i] = fib[i-1] + fib[i-2];
      if(fib[i]%2)
        sum += fib[i];
      i++;
    }
  if(fib[i-1]%2)
    return sum-fib[i-1];
  else
    return sum;
}

sumFibs(75025);

#2

Given a positive integer num, return the sum of all odd Fibonacci numbers that are less than or equal to num.

Given that 75025 is a Fibonacci number, it should be included in the sum.


#3

thanks. I didn’t see the equality