From 7c157bdc29e380b729506802d2311a2bf2291255 Mon Sep 17 00:00:00 2001 From: NetMan <13informatyka14@gmail.com> Date: Thu, 11 Jan 2024 21:37:42 +0100 Subject: [PATCH] Added 2 tests, fixed first numbers and passed them in exercise 10 --- 10_fibonacci/fibonacci.js | 7 ++++--- 10_fibonacci/fibonacci.spec.js | 6 ++++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/10_fibonacci/fibonacci.js b/10_fibonacci/fibonacci.js index fb278ac..38f2021 100644 --- a/10_fibonacci/fibonacci.js +++ b/10_fibonacci/fibonacci.js @@ -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; diff --git a/10_fibonacci/fibonacci.spec.js b/10_fibonacci/fibonacci.spec.js index caedfdf..6601caf 100644 --- a/10_fibonacci/fibonacci.spec.js +++ b/10_fibonacci/fibonacci.spec.js @@ -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); });