Skip to content

Commit bbac5b1

Browse files
committed
factorial
1 parent 55d6ed2 commit bbac5b1

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

Programs/DSA/factorial.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
3+
5. WAP in js factorial
4+
5+
5 =120
6+
*/
7+
8+
9+
10+
11+
function factorial(num) {
12+
13+
if (num === 0 || num === 1) {
14+
15+
return 1
16+
} else {
17+
18+
return num * factorial(num - 1)
19+
}
20+
}
21+
console.log(factorial(5))//120

0 commit comments

Comments
 (0)