function generateFibSeq(num){
var arr=[1,1];
while(num > arr[arr.length-1]){
if(arr[arr.length-1]+arr[arr.length-2] > num){
break;
}
arr.push(arr[arr.length-1]+arr[arr.length-2]);
}
return arr;
}
function sumFibs(num) {
if(num===1){
return 1;
}
var fibArr = generateFibSeq(num);
var sum = 0;
for(var i in fibArr){
if(fibArr[i]%2 !== 0){
sum += fibArr[i];
}
}
return sum;
}
sumFibs(75025);
No comments:
Post a Comment