diff --git a/08_calculator/calculator.js b/08_calculator/calculator.js index a89ce8c..28a6476 100644 --- a/08_calculator/calculator.js +++ b/08_calculator/calculator.js @@ -6,8 +6,11 @@ const subtract = function(a, b) { return a - b; }; -const sum = function() { - +const sum = function(array) { + const output = array.reduce((total, value) => { + return total + value; + }, 0); + return output; }; const multiply = function() { diff --git a/08_calculator/calculator.spec.js b/08_calculator/calculator.spec.js index 996f4c9..33e9367 100644 --- a/08_calculator/calculator.spec.js +++ b/08_calculator/calculator.spec.js @@ -21,19 +21,19 @@ describe('subtract', () => { }); describe('sum', () => { - test.skip('computes the sum of an empty array', () => { + test('computes the sum of an empty array', () => { expect(calculator.sum([])).toBe(0); }); - test.skip('computes the sum of an array of one number', () => { + test('computes the sum of an array of one number', () => { expect(calculator.sum([7])).toBe(7); }); - test.skip('computes the sum of an array of two numbers', () => { + test('computes the sum of an array of two numbers', () => { expect(calculator.sum([7, 11])).toBe(18); }); - test.skip('computes the sum of an array of many numbers', () => { + test('computes the sum of an array of many numbers', () => { expect(calculator.sum([1, 3, 5, 7, 9])).toBe(25); }); });