Skip to content

Commit b83abac

Browse files
authored
Merge pull request knaxus#94 from iamvalentin23/master
Added factorial problem and solution
2 parents 1387eef + 8b6edf9 commit b83abac

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/_Problems_/factorial/index.js

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
function factorial(num) {
2+
if (num === 1) return num;
3+
else return num * factorial(num - 1);
4+
}
5+
6+
module.exports = {
7+
factorial,
8+
};
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
const { factorial } = require('.');
2+
3+
describe('Factorial', () => {
4+
it('Should return 24', () => {
5+
expect(factorial(4)).toEqual(24);
6+
});
7+
8+
it('Should return 1', () => {
9+
expect(factorial(1)).toEqual(1);
10+
});
11+
12+
it('Should return 120', () => {
13+
expect(factorial(5)).toEqual(120);
14+
});
15+
});

0 commit comments

Comments
 (0)