Hi together
It took me a few days, but I passed the “Sum All Odd Fibonaccis” Challenge.
I have 2 Questions:
1 How good/bad is my code (I think not to bad)?
2 Actually it should be possible to get all Fibonacci Numbers by using Recursion. But can I use Recursion to solve this challenge too? Including just sum the odd Numbers?
Your code so far
function sumFibs(num) {
let fibs = [1 ,1], temp = fibs[fibs.length - 1];
while (temp <= num) {
temp += fibs[fibs.length - 2];
if (temp <= num) fibs.push(temp);
}
return fibs.reduce((accumulator, current) => {
return ((current % 2) !== 0) ? (accumulator + current) : (accumulator + 0);
});
}
sumFibs(4);
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:85.0) Gecko/20100101 Firefox/85.0
.
Challenge: Sum All Odd Fibonacci Numbers
Link to the challenge: