We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents 1387eef + 8b6edf9 commit b83abacCopy full SHA for b83abac
src/_Problems_/factorial/index.js
@@ -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
+ };
src/_Problems_/factorial/index.test.js
@@ -0,0 +1,15 @@
+const { factorial } = require('.');
+describe('Factorial', () => {
+ it('Should return 24', () => {
+ expect(factorial(4)).toEqual(24);
+ });
+ 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