it('returns sum of all odd Fibonnci numbers 2nd example', () => {
const num = 1000;
const result = sumOddFibonacciNumbers(num);
console.log("result 2: ", result);
expect(result).toBe(1785);
});
it('returns sum of all odd Fibonnci numbers 3rd example', () => {
const num = 4000000;
const result = sumOddFibonacciNumbers(num);
console.log("result 2: ", result);
expect(result).toBe(4613732);
});
});
function sumOddFibonacciNumbers(num) {
let fibPrev=1;
let fib=0;
let sum=0;
while (fibPrev < num) {
[ fibPrev, fib ] = [fib + fibPrev, fibPrev];
if (fib % 2 != 0) {
sum += fib;
}
}
return sum;
}
/**
* Test Suite
*/
describe('sumOddFibonacciNumbers()', () => {
it('returns sum of all odd Fibonnci numbers', () => {
const num = 10;
const result = sumOddFibonacciNumbers(num);
console.log("result 1: ", result);
expect(result).toBe(10);
});