Added 2 tests, fixed first numbers and passed them in exercise 10

This commit is contained in:
NetMan 2024-01-11 21:37:42 +01:00
parent ad1ef473d6
commit 7c157bdc29
2 changed files with 10 additions and 3 deletions

View File

@ -1,6 +1,7 @@
const fibonacci = function(number, b) {
let sum;
for (let i = 0, a = 1, b = 1;
const fibonacci = function(number) {
let a = 1, b = 1;
let sum = a;
for (let i = 0;
i < number - 2;
i++, (i % 2 == 0) ? a = sum : b = sum) {
sum = a + b;

View File

@ -16,6 +16,12 @@ describe('fibonacci', () => {
test('25th fibonacci number is 75025', () => {
expect(fibonacci(25)).toBe(75025);
});
test('1st fibonacci number is 1', () => {
expect(fibonacci(1)).toBe(1);
});
test('2nd fibonacci number is 1', () => {
expect(fibonacci(2)).toBe(1);
});
test.skip('0th fibonacci number is 0', () => {
expect(fibonacci(0)).toBe(0);
});