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>
This commit is contained in:
Croustys
2020-10-14 04:02:26 +02:00
committed by GitHub
parent 63e6e06664
commit cd7111a015

16
Recursive/factorial.js Normal file
View File

@ -0,0 +1,16 @@
// 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))