Passed "sum" using reduce() array method in exercise 08
This commit is contained in:
parent
f4e1b0d95a
commit
bcd6da249a
|
@ -6,8 +6,11 @@ const subtract = function(a, b) {
|
||||||
return 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() {
|
const multiply = function() {
|
||||||
|
|
|
@ -21,19 +21,19 @@ describe('subtract', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('sum', () => {
|
describe('sum', () => {
|
||||||
test.skip('computes the sum of an empty array', () => {
|
test('computes the sum of an empty array', () => {
|
||||||
expect(calculator.sum([])).toBe(0);
|
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);
|
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);
|
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);
|
expect(calculator.sum([1, 3, 5, 7, 9])).toBe(25);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue