JavaScript Fatorial
function factorial(n) {
if (n < 0) return;
if (n < 2) return 1;
return n * factorial(n - 1);
}
TC5550
function factorial(n) {
if (n < 0) return;
if (n < 2) return 1;
return n * factorial(n - 1);
}
function factorial(n) {
return (n + 1) * (n / 2);
}
function factorialize(num) {
var result = num;
if (num === 0 || num === 1)
return 1;
while (num > 1) {
num--;
result *= num;
}
return result;
}
function factorialize(num) {
if(num < 2) return 1;
return num *= factorialize(num - 1);
}
function getFact(number) {
let fact = 1;
for (var i = 1; i <= number; i++) {
fact = fact * i;
}
return fact;
}
console.log(getFact(5))
//Output: 120
const factorial = n => n <= 1 ? 1 : n * factorial(n - 1);
// Examples
factorial(2); // 2
factorial(3); // 6