Add factorialRecursiveTCO

This commit is contained in:
trainer2001 2021-12-12 15:39:32 +05:30
parent 9bb60fa72f
commit 4ea1ad0bb8

View 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);
}