Intermediate Algorithm Scripting: Fibonacci Numbers

What do you guys think about this algorithm that answers to the challenge of Fibonacci numbers in advanced JS algorithm scripting? I am a beginner and would like to hear your thoughts. How much time did it take you to solve it? My take on this was about one hour (kinda tired today). Thanks in advance!

function sumFibs(num) {
  let count = [1];
  let sum = 2;
  for(let i = 1; i < num; i++) { count.push(i); }

  for(let i = 3; i < num; i++) {
    let next = count[i - 1] + count[i - 2];
    count.splice(i, 1, next); 
    (count[i] % 2 != 0 && count[i] <= num) ? sum += count[i] : null;
  }

  return sum;
}

console.log(sumFibs(400));

Hi @Marko-91, welcome back. In the future please surround answers to solutions with the [spoiler] [/spoiler] tags so it’s blurred for someone who has not completed the challenge or, does not want to see the solution.

1 Like