Tell us what’s happening:
Hi all,
I passed all the test cases except one, is something wrong with my code or the test case?
sumFibs(75024)
should return 60696.
sumFibs(75025)
should return 135721.
Passed the first test case but the second one failed. There is only one digit difference between the two inputs the output is totally different. For the input(75025) I am having the same output of 60696
Your code so far
function sumFibs(num) {
// first two numbers of series
let fibonacci = [0, 1];
let num1 = 0;
let num2 = 1;
// add fibonacci series number in the array
for(let i = 0; i < num; i++){
fibonacci.push(num1 + num2);
let sum = num1 + num2;
num1 = num2;
num2 = sum;
}
// filter array as number should be odd and smaller than input
let oddFibo = fibonacci.filter((number) => number%2 != 0 && number < num);
// sum of all odd numbers in series
let sum = oddFibo.reduce((a,b) => a + b, 0);
console.log(sum);
return sum;
}
sumFibs(75025);
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.146 Safari/537.36
.
Challenge: Sum All Odd Fibonacci Numbers
Link to the challenge: