Add files via upload
This commit is contained in:
parent
cb46ea9e2d
commit
71313b1d93
|
@ -1,17 +1,29 @@
|
||||||
const add = function() {
|
const add = function(a, b) {
|
||||||
|
return a + b;
|
||||||
};
|
};
|
||||||
|
|
||||||
const subtract = function() {
|
const subtract = function(a, b) {
|
||||||
|
return a - b;
|
||||||
};
|
};
|
||||||
|
|
||||||
const sum = function() {
|
const sum = function(array) {
|
||||||
|
let sumArray = 0;
|
||||||
|
if (array.length == 0) {
|
||||||
|
return 0;
|
||||||
|
} else {
|
||||||
|
for (let i = 0; i < array.length; i++) {
|
||||||
|
sumArray += array[i];
|
||||||
|
}
|
||||||
|
return sumArray;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const multiply = function() {
|
const multiply = function(numbers) {
|
||||||
|
let multiplyNum = 1;
|
||||||
|
for (let i = 0; i < numbers.length; i++) {
|
||||||
|
multiplyNum *= numbers[i];
|
||||||
|
}
|
||||||
|
return multiplyNum;
|
||||||
};
|
};
|
||||||
|
|
||||||
const power = function() {
|
const power = function() {
|
||||||
|
|
|
@ -5,45 +5,45 @@ describe('add', () => {
|
||||||
expect(calculator.add(0,0)).toBe(0);
|
expect(calculator.add(0,0)).toBe(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
test.skip('adds 2 and 2', () => {
|
test('adds 2 and 2', () => {
|
||||||
expect(calculator.add(2,2)).toBe(4);
|
expect(calculator.add(2,2)).toBe(4);
|
||||||
});
|
});
|
||||||
|
|
||||||
test.skip('adds positive numbers', () => {
|
test('adds positive numbers', () => {
|
||||||
expect(calculator.add(2,6)).toBe(8);
|
expect(calculator.add(2,6)).toBe(8);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('subtract', () => {
|
describe('subtract', () => {
|
||||||
test.skip('subtracts numbers', () => {
|
test('subtracts numbers', () => {
|
||||||
expect(calculator.subtract(10,4)).toBe(6);
|
expect(calculator.subtract(10,4)).toBe(6);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
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);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
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);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue