From e62fd9013ca9234b91856c5b063419be2b7cd5ed Mon Sep 17 00:00:00 2001 From: NetMan <13informatyka14@gmail.com> Date: Thu, 11 Jan 2024 10:00:30 +0100 Subject: [PATCH] Passed "multiply" using reduce() array method in exercise 08 --- 08_calculator/calculator.js | 7 +++++-- 08_calculator/calculator.spec.js | 4 ++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/08_calculator/calculator.js b/08_calculator/calculator.js index 28a6476..f405111 100644 --- a/08_calculator/calculator.js +++ b/08_calculator/calculator.js @@ -13,8 +13,11 @@ const sum = function(array) { return output; }; -const multiply = function() { - +const multiply = function(array) { + const output = array.reduce((multiplification, value) => { + return multiplification * value; + }, 1); + return output; }; const power = function() { diff --git a/08_calculator/calculator.spec.js b/08_calculator/calculator.spec.js index 33e9367..32fe258 100644 --- a/08_calculator/calculator.spec.js +++ b/08_calculator/calculator.spec.js @@ -39,11 +39,11 @@ describe('sum', () => { }); describe('multiply', () => { - test.skip('multiplies two numbers', () => { + test('multiplies two numbers', () => { expect(calculator.multiply([2, 4])).toBe(8); }); - test.skip('multiplies several numbers', () => { + test('multiplies several numbers', () => { expect(calculator.multiply([2, 4, 6, 8, 10, 12, 14])).toBe(645120); }); });