function factorial(num) { let result = 1; while (num > 1) { result *= num; num--; } return result; } factorial(3); // 6
function factorial(num) { if (num <= 1) return 1; return num * factorial(num - 1); } factorial(3); // 6