mirror of
https://github.moeyy.xyz/https://github.com/trekhleb/javascript-algorithms.git
synced 2024-11-10 11:09:43 +08:00
Add factorialRecursiveTCO
This commit is contained in:
parent
9bb60fa72f
commit
4ea1ad0bb8
12
src/algorithms/math/factorial/factorialRecursiveTCO.js
Normal file
12
src/algorithms/math/factorial/factorialRecursiveTCO.js
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
/**
|
||||||
|
* @param {number} number
|
||||||
|
* @return {number}
|
||||||
|
*/
|
||||||
|
export default function factorialRecursiveTCO(number) {
|
||||||
|
function fact(number, accumulator = 1) {
|
||||||
|
if (number < 2) return accumulator;
|
||||||
|
else return fact(number - 1, accumulator * number);
|
||||||
|
}
|
||||||
|
|
||||||
|
return fact(number);
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user