Skip to content

Commit 51415f8

Browse files
merge: Add test case (#851)
* Add test case * minor fix * delete files * rename file
1 parent c33b19a commit 51415f8

File tree

3 files changed

+29
-11
lines changed

3 files changed

+29
-11
lines changed

Recursive/Factorial.js

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* @function Factorial
3+
* @description function to find factorial using recursion.
4+
* @param {Integer} n - The input integer
5+
* @return {Integer} - Factorial of n.
6+
* @see [Factorial](https://en.wikipedia.org/wiki/Factorial)
7+
* @example 5! = 1*2*3*4*5 = 120
8+
* @example 2! = 1*2 = 2
9+
*/
10+
11+
const factorial = (n) => {
12+
if (n === 0) {
13+
return 1
14+
}
15+
return n * factorial(n - 1)
16+
}
17+
18+
export { factorial }

Recursive/factorial.js

-11
This file was deleted.

Recursive/test/Factorial.test.js

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { factorial } from '../Factorial'
2+
3+
describe('Factorial', () => {
4+
it('should return factorial 1 for value "0"', () => {
5+
expect(factorial(0)).toBe(1)
6+
})
7+
8+
it('should return factorial 120 for value "5"', () => {
9+
expect(factorial(5)).toBe(120)
10+
})
11+
})

0 commit comments

Comments
 (0)