mirror of
https://github.com/10h30/odin-javascript-exercises.git
synced 2026-06-05 15:09:09 +09:00
Corrected solution to factorial function
This commit is contained in:
@@ -19,12 +19,10 @@ function power(a, b) {
|
||||
}
|
||||
|
||||
function factorial(n) {
|
||||
if (n == 0) return 0;
|
||||
let product = 1;
|
||||
for (let i = n; i > 0; i--) {
|
||||
product *= i;
|
||||
}
|
||||
return product;
|
||||
if (n===0){
|
||||
return 1;
|
||||
}
|
||||
return n * factorial (n-1);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
|
||||
Reference in New Issue
Block a user