[sumOddFibonacci]tests fail

*code works
*i optimized it using the globalFibArr
*but the tests fail although it doesnt time out

const globalFibArr = [0,1]
let firstTime = true
function fib(n) {
  if(firstTime){n++;firstTime=false}
  if(globalFibArr[n-1]==undefined){
    let result = fib(n-1)+fib(n-2)
    globalFibArr.push(result)
    return result
  }else{return globalFibArr[n-1]}
}
function sumFibs(n){
  fib(n)
  return globalFibArr
           .filter(i=>(i%2)==1)
           .reduce((a,b)=>a+b) }

i forgot to check if i <= n
solution code:

const fibIndex = [0,1]
function sumFibs(n){
  let i=2
  while(i<=n){
    fibIndex.push(fibIndex[i-1]+fibIndex[i-2])
    i++
  } return fibIndex
           .filter(i=>i<=n&&(i%2)==1)
           .reduce((a,b)=>a+b)}