mirror of
https://github.moeyy.xyz/https://github.com/trekhleb/javascript-algorithms.git
synced 2024-11-13 06:23:00 +08:00
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:
parent
76617fa83a
commit
a906b7ed69
@ -11,3 +11,16 @@ export default function factorial(number) {
|
|||||||
|
|
||||||
return result;
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user