File tree 3 files changed +29
-11
lines changed
3 files changed +29
-11
lines changed Original file line number Diff line number Diff line change
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 }
Load Diff This file was deleted.
Original file line number Diff line number Diff line change
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
+ } )
You can’t perform that action at this time.
0 commit comments