mirror of
https://github.com/TheAlgorithms/JavaScript.git
synced 2025-07-19 10:05:41 +08:00
12 lines
217 B
JavaScript
12 lines
217 B
JavaScript
// function to find factorial using recursion
|
|
// example :
|
|
// 5! = 1*2*3*4*5 = 120
|
|
// 2! = 1*2 = 2
|
|
|
|
export const factorial = (n) => {
|
|
if (n === 0) {
|
|
return 1
|
|
}
|
|
return n * factorial(n - 1)
|
|
}
|