Skip to content

Commit 9599e2a

Browse files
Merge pull request #369 from cats256/cats256-branch
Reformat test parameters for consistency
2 parents e381086 + 44e39f0 commit 9599e2a

File tree

2 files changed

+51
-55
lines changed

2 files changed

+51
-55
lines changed

08_calculator/calculator.spec.js

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,77 @@
11
const calculator = require('./calculator');
22

33
describe('add', () => {
4-
test('adds 0 and 0', () => {
5-
expect(calculator.add(0,0)).toBe(0);
6-
});
4+
test('adds 0 and 0', () => {
5+
expect(calculator.add(0, 0)).toBe(0);
6+
});
77

8-
test.skip('adds 2 and 2', () => {
9-
expect(calculator.add(2,2)).toBe(4);
10-
});
8+
test.skip('adds 2 and 2', () => {
9+
expect(calculator.add(2, 2)).toBe(4);
10+
});
1111

12-
test.skip('adds positive numbers', () => {
13-
expect(calculator.add(2,6)).toBe(8);
14-
});
12+
test.skip('adds positive numbers', () => {
13+
expect(calculator.add(2, 6)).toBe(8);
14+
});
1515
});
1616

1717
describe('subtract', () => {
18-
test.skip('subtracts numbers', () => {
19-
expect(calculator.subtract(10,4)).toBe(6);
20-
});
18+
test.skip('subtracts numbers', () => {
19+
expect(calculator.subtract(10, 4)).toBe(6);
20+
});
2121
});
2222

2323
describe('sum', () => {
24-
test.skip('computes the sum of an empty array', () => {
25-
expect(calculator.sum([])).toBe(0);
26-
});
24+
test.skip('computes the sum of an empty array', () => {
25+
expect(calculator.sum([])).toBe(0);
26+
});
2727

28-
test.skip('computes the sum of an array of one number', () => {
29-
expect(calculator.sum([7])).toBe(7);
30-
});
28+
test.skip('computes the sum of an array of one number', () => {
29+
expect(calculator.sum([7])).toBe(7);
30+
});
3131

32-
test.skip('computes the sum of an array of two numbers', () => {
33-
expect(calculator.sum([7,11])).toBe(18);
34-
});
32+
test.skip('computes the sum of an array of two numbers', () => {
33+
expect(calculator.sum([7, 11])).toBe(18);
34+
});
3535

36-
test.skip('computes the sum of an array of many numbers', () => {
37-
expect(calculator.sum([1,3,5,7,9])).toBe(25);
38-
});
36+
test.skip('computes the sum of an array of many numbers', () => {
37+
expect(calculator.sum([1, 3, 5, 7, 9])).toBe(25);
38+
});
3939
});
4040

4141
describe('multiply', () => {
42-
test.skip('multiplies two numbers', () => {
43-
expect(calculator.multiply(2,4)).toBe(8);
44-
});
42+
test.skip('multiplies two numbers', () => {
43+
expect(calculator.multiply([2, 4])).toBe(8);
44+
});
4545

46-
test.skip('multiplies several numbers', () => {
47-
expect(calculator.multiply(2,4,6,8,10,12,14)).toBe(645120);
48-
});
46+
test.skip('multiplies several numbers', () => {
47+
expect(calculator.multiply([2, 4, 6, 8, 10, 12, 14])).toBe(645120);
48+
});
4949
});
5050

5151
describe('power', () => {
52-
test.skip('raises one number to the power of another number', () => {
53-
expect(calculator.power(4,3)).toBe(64); // 4 to third power is 64
54-
});
52+
test.skip('raises one number to the power of another number', () => {
53+
expect(calculator.power(4, 3)).toBe(64); // 4 to third power is 64
54+
});
5555
});
5656

5757
describe('factorial', () => {
58-
test.skip('computes the factorial of 0', () => {
59-
expect(calculator.factorial(0)).toBe(1); // 0! = 1
60-
});
58+
test.skip('computes the factorial of 0', () => {
59+
expect(calculator.factorial(0)).toBe(1); // 0! = 1
60+
});
6161

62-
test.skip('computes the factorial of 1', () => {
63-
expect(calculator.factorial(1)).toBe(1);
64-
});
62+
test.skip('computes the factorial of 1', () => {
63+
expect(calculator.factorial(1)).toBe(1);
64+
});
6565

66-
test.skip('computes the factorial of 2', () => {
67-
expect(calculator.factorial(2)).toBe(2);
68-
});
66+
test.skip('computes the factorial of 2', () => {
67+
expect(calculator.factorial(2)).toBe(2);
68+
});
6969

70-
test.skip('computes the factorial of 5', () => {
71-
expect(calculator.factorial(5)).toBe(120);
72-
});
70+
test.skip('computes the factorial of 5', () => {
71+
expect(calculator.factorial(5)).toBe(120);
72+
});
7373

74-
test.skip('computes the factorial of 10', () => {
75-
expect(calculator.factorial(10)).toBe(3628800);
76-
});
74+
test.skip('computes the factorial of 10', () => {
75+
expect(calculator.factorial(10)).toBe(3628800);
76+
});
7777
});

08_calculator/solution/calculator-solution.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,9 @@ const sum = function (array) {
1010
return array.reduce((total, current) => total + current, 0);
1111
};
1212

13-
const multiply = function(...args){
14-
let product = 1;
15-
for (let i = 0; i < args.length; i++) {
16-
product *= args[i];
17-
}
18-
return product;
19-
};
13+
const multiply = function (array) {
14+
return array.reduce((product, current) => product * current)
15+
};
2016

2117
const power = function (a, b) {
2218
return Math.pow(a, b);

0 commit comments

Comments
 (0)