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); });