// Factorialize a Number
function factorialize(num) {
if (num === 0) return 1;
return num * factorialize(num - 1);
}
factorialize(5);
// OR with Tail Call Optimization (https://stackoverflow.com/questions/33923/what-is-tail-recursion)
function factorialize(num, factorial = 1) {
if (num == 0) {
return factorial;
} else {
return factorialize(num - 1, factorial * num);
}
}
factorialize(5);