diff --git a/08_calculator/calculator.js b/08_calculator/calculator.js index 12dd568..cebeaf5 100644 --- a/08_calculator/calculator.js +++ b/08_calculator/calculator.js @@ -24,8 +24,11 @@ const power = function(a, x) { return 4 ** 3; }; -const factorial = function() { - +const factorial = function(a) { + if (a <= 1) { + return 1; + } + return a * factorial(a - 1); }; // Do not edit below this line diff --git a/08_calculator/calculator.spec.js b/08_calculator/calculator.spec.js index 119673a..59956fe 100644 --- a/08_calculator/calculator.spec.js +++ b/08_calculator/calculator.spec.js @@ -55,23 +55,23 @@ describe('power', () => { }); describe('factorial', () => { - test.skip('computes the factorial of 0', () => { + test('computes the factorial of 0', () => { expect(calculator.factorial(0)).toBe(1); // 0! = 1 }); - test.skip('computes the factorial of 1', () => { + test('computes the factorial of 1', () => { expect(calculator.factorial(1)).toBe(1); }); - test.skip('computes the factorial of 2', () => { + test('computes the factorial of 2', () => { expect(calculator.factorial(2)).toBe(2); }); - test.skip('computes the factorial of 5', () => { + test('computes the factorial of 5', () => { expect(calculator.factorial(5)).toBe(120); }); - test.skip('computes the factorial of 10', () => { + test('computes the factorial of 10', () => { expect(calculator.factorial(10)).toBe(3628800); }); });