Https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/sum-all-odd-fibonacci-numbers

function sumFibs(num) {
  const newArr = [];
  for (let i = 0; i <= num; i++) {
    if (i <= 1) {
      newArr.push(1)
    } else {
      let current = 0;
      for (let j = 0; j < newArr.length; j++) {
         current = newArr[j] + newArr[j - 1];
        //console.log(current)
      }
      i = current;
      newArr.push(current)
    }
  }
  return newArr.filter((item)=> {
   const myArr = item <= num && item % 2 !== 0
   return myArr
  }).reduce((total, item)=> {
    return total += item
  });

}

console.log(sumFibs(10));
1 Like

Hey there, do you have a question here?

Hey there ilenia. I found this post. I was sharing my solution to find and add all odd Fibonacci series problems on the freecodecamp. I want to ask you if you have any idea how I could improve my code.

I would avoid creating an array