Passed "multiply" using reduce() array method in exercise 08

This commit is contained in:
NetMan 2024-01-11 10:00:30 +01:00
parent bcd6da249a
commit e62fd9013c
2 changed files with 7 additions and 4 deletions

View File

@ -13,8 +13,11 @@ const sum = function(array) {
return output; return output;
}; };
const multiply = function() { const multiply = function(array) {
const output = array.reduce((multiplification, value) => {
return multiplification * value;
}, 1);
return output;
}; };
const power = function() { const power = function() {

View File

@ -39,11 +39,11 @@ describe('sum', () => {
}); });
describe('multiply', () => { describe('multiply', () => {
test.skip('multiplies two numbers', () => { test('multiplies two numbers', () => {
expect(calculator.multiply([2, 4])).toBe(8); 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); expect(calculator.multiply([2, 4, 6, 8, 10, 12, 14])).toBe(645120);
}); });
}); });