Add files via upload

This commit is contained in:
reddforman 2022-11-11 09:11:57 -08:00 committed by GitHub
parent cb46ea9e2d
commit 71313b1d93
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 17 deletions

View File

@ -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() {

View File

@ -5,45 +5,45 @@ describe('add', () => {
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);
});
test.skip('adds positive numbers', () => {
test('adds positive numbers', () => {
expect(calculator.add(2,6)).toBe(8);
});
});
describe('subtract', () => {
test.skip('subtracts numbers', () => {
test('subtracts numbers', () => {
expect(calculator.subtract(10,4)).toBe(6);
});
});
describe('sum', () => {
test.skip('computes the sum of an empty array', () => {
test('computes the sum of an empty array', () => {
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);
});
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);
});
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);
});
});
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);
});
});