Added a recursive solution to factorial problem

i added a recursive code under your iterative code. Please merge it to your code
This commit is contained in:
Shashi3k 2023-08-26 23:25:34 +05:30 committed by GitHub
parent 76617fa83a
commit a906b7ed69
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -11,3 +11,16 @@ export default function factorial(number) {
return result;
}
/**
* @param {number} number
* @return {number}
* Recursive solution
*/
export default function factorial(number){
if (number>=1){
return number*factorial(number-1);
}
else{
return 1
}
}