Files
JavaScript/Recursive/factorial.js
Croustys cd7111a015 Added tests & normal function convertion (#445)
* added factorial calculator recursively

* added tests and converted to normal function

* Added tests & normal function convertion

* Update factorialCalculator.js

updated code "design" not sure why test fails on such arbitrary things.

* Update and rename factorialCalculator.js to factorial.js

Co-authored-by: vinayak <itssvinayak@gmail.com>
2020-10-14 07:32:26 +05:30

17 lines
306 B
JavaScript

// function to find factorial using recursion
// example :
// 5! = 1*2*3*4*5 = 120
// 2! = 1*2 = 2
const factorial = (n) => {
if (n === 0) {
return 1
}
return n * factorial(n - 1)
}
// testing
console.log(factorial(4))
console.log(factorial(15))
console.log(factorial(0))