scrimba
Solution for day 9 of #javascriptmas
Go Pro!Bootcamp

Bootcamp

Study group

Collaborate with peers in your dedicated #study-group channel.

Code reviews

Submit projects for review using the /review command in your #code-reviews channel

Solution for day 9 of #javascriptmas
AboutCommentsNotes
Solution for day 9 of #javascriptmas
Expand for more info
main.js
run
preview
console
function sumOddFibonacciNumbers(num) {
let fibo = [0,1]
for (i = 1; i<num; i++) {
fibo.push(fibo[i] + fibo[i - 1])
}

return fibo.filter(a => a <= num && a%2 !== 0).reduce((x,y) => x + y)

}



/**
* Test Suite
*/
describe('sumOddFibonacciNumbers()', () => {
it('returns sum of all odd Fibonnci numbers', () => {
// arrange
const num = 10;

// act
const result = sumOddFibonacciNumbers(num);

// log
console.log("result 1: ", result);

// assert
expect(result).toBe(10);
});

it('returns sum of all odd Fibonnci numbers 2nd example', () => {
// arrange
const num = 1000;

// act
const result = sumOddFibonacciNumbers(num);

// log
console.log("result 2: ", result);

// assert
expect(result).toBe(1785);
});
});
Console
"result 1: "
,
10
,
"result 2: "
,
1785
,
/index.html
LIVE