This commit is contained in:
endritibra 2022-06-02 19:36:09 +02:00
parent e0275b086e
commit 9f16158f53
2 changed files with 29 additions and 16 deletions

View File

@ -1,6 +1,6 @@
const add = function() { const add=(num1,num2)=>{
return num1+num2;
}; }
const subtract = function() { const subtract = function() {
@ -14,13 +14,26 @@ const multiply = function() {
}; };
const power = function() { const power = function(num,power) {
let rez=1;
for(let i=1;i<=power;i++){
rez*=num;
}; };
return rez
}
const factorial = function() {
}; const factorial = (num) =>{
let res=1;
for(i=1;i<=num;i++){
res*=i;
}
return res;
}
// Do not edit below this line // Do not edit below this line
module.exports = { module.exports = {

View File

@ -5,11 +5,11 @@ 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);
}); });
}); });
@ -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);
}); });
}); });