Sum All Odd Fibonacci Numbers, fails on 2 of 6 test [SOLVED]

This code works on a sequences but the 1000 and 75025 test. What am I missing?

var total = function(arr, type){
  var rtn = 0;
  switch(type){
    case 'odd':
      arr.forEach(function(val){
        if( val%2 !== 0 ){
          rtn+=val;
        }
      });
      break;
      
    default:
      arr.forEach(function(val){
        rtn+=val;
      });
  }
  return rtn;
};


var add = function(arr){
  var max = arr.length;
  return arr[max-2] + arr[max-1];
};


function sumFibs(num) {
  var fib = [1,1];
  var val = 0;
  var rtn = 0;
  
  while(total(fib,'all') <= num){
    fib.push(add(fib));
  }
  
  rtn = total(fib,'odd');
  
  return rtn;
}

sumFibs(1000);

never mind, I figured it out.

1 Like