Merge pull request #9 from ThirtyThreeB/patch-1

Corrected solution to factorial function
This commit is contained in:
Cody Loyd 2018-01-03 12:22:13 -06:00 committed by GitHub
commit b14ac4ea17
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -19,7 +19,7 @@ function power(a, b) {
} }
function factorial(n) { function factorial(n) {
if (n == 0) return 0; if (n == 0) return 1;
let product = 1; let product = 1;
for (let i = n; i > 0; i--) { for (let i = n; i > 0; i--) {
product *= i; product *= i;
@ -27,6 +27,15 @@ function factorial(n) {
return product; return product;
} }
// This is another implementation of Factorial that uses recursion
// THANKS to @ThirtyThreeB!
function recursiveFactorial(n) {
if (n===0){
return 1;
}
return n * factorial (n-1);
}
module.exports = { module.exports = {
add, add,
subtract, subtract,