I am very, very confused.
Here is my code, it’s may not be the prettiest because I was doing it recursively without looking it up so it’s not as concise as it could be:
var arr = [];
function sumFibs(num) {
//create array of Fibonacci numbers
fib(0, 1, num);
//add 1 at the beginning and remove the last number (it's above num)
arr.pop();
arr.unshift(1);
//get the odd numbers
results = [];
results = arr.filter(function(element) {
return element % 2 == 1;
});
//sum the odd numbers
var sum = 0;
for(var i = 0; i < results.length; i++) {
sum += results[i];
}
//return 60696 === sum; //true
return sum;
}
function fib(num1, num2, stopNum) {
sum = num1 + num2;
arr.push(sum);
while(sum <= stopNum) { //last number will need to be taken out
return fib(num2, sum, stopNum);
}
}
sumFibs(75024);
sumFibs(75024) returns 60696 - which looks a lot like the correct answer of 60696. As you can see in my code I have commented out sum === 60696, which returns true. But when I return sum the only requirement I fulfill is that “sumFibs(1) should return a number”, everything else is wrong even though it really really looks like it is returning the correct results. What stupid, dumb thing am I missing?