Add files via upload

This commit is contained in:
reddforman 2022-11-14 08:13:04 -08:00 committed by GitHub
parent 71313b1d93
commit 614b9ff903
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 14 deletions

View File

@ -11,11 +11,11 @@ const sum = function(array) {
if (array.length == 0) { if (array.length == 0) {
return 0; return 0;
} else { } else {
for (let i = 0; i < array.length; i++) { for (let i = 0; i < array.length; i++) {
sumArray += array[i]; sumArray += array[i];
}
return sumArray;
} }
return sumArray;
}
}; };
const multiply = function(numbers) { const multiply = function(numbers) {
@ -26,12 +26,20 @@ const multiply = function(numbers) {
return multiplyNum; return multiplyNum;
}; };
const power = function() { const power = function(num, power) {
powerNum = 1;
for (let i = 0; i < power; i++) {
powerNum *= num;
}
return powerNum;
}; };
const factorial = function() { const factorial = function(fact) {
factNum = 1;
for (let i = fact; i > 0; i--) {
factNum *= i;
}
return factNum;
}; };
// Do not edit below this line // Do not edit below this line

View File

@ -49,29 +49,29 @@ describe('multiply', () => {
}); });
describe('power', () => { describe('power', () => {
test.skip('raises one number to the power of another number', () => { test('raises one number to the power of another number', () => {
expect(calculator.power(4,3)).toBe(64); // 4 to third power is 64 expect(calculator.power(4,3)).toBe(64); // 4 to third power is 64
}); });
}); });
describe('factorial', () => { describe('factorial', () => {
test.skip('computes the factorial of 0', () => { test('computes the factorial of 0', () => {
expect(calculator.factorial(0)).toBe(1); // 0! = 1 expect(calculator.factorial(0)).toBe(1); // 0! = 1
}); });
test.skip('computes the factorial of 1', () => { test('computes the factorial of 1', () => {
expect(calculator.factorial(1)).toBe(1); expect(calculator.factorial(1)).toBe(1);
}); });
test.skip('computes the factorial of 2', () => { test('computes the factorial of 2', () => {
expect(calculator.factorial(2)).toBe(2); expect(calculator.factorial(2)).toBe(2);
}); });
test.skip('computes the factorial of 5', () => { test('computes the factorial of 5', () => {
expect(calculator.factorial(5)).toBe(120); expect(calculator.factorial(5)).toBe(120);
}); });
test.skip('computes the factorial of 10', () => { test('computes the factorial of 10', () => {
expect(calculator.factorial(10)).toBe(3628800); expect(calculator.factorial(10)).toBe(3628800);
}); });
}); });