function factorial(n) {
if (n < 0) return;
if (n < 2) return 1;
return n * factorial(n - 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
function factorial(n) {
if (n > 1) {
return n * factorial(n - 1);
}
return 1;
}
const factorialize = num => {
if (num === 0 || num === 1) {
return 1;
}
for (let i = num - 1; i >= 1; i--) {
num *= i;
}
return num;
};
num = 5
factorialn = 1
function factorial() {
for (i = 1; i <= num; i++) {
factorialn *= i
}
}
factorial()
console.log(factorialn)
function factorial(n) {
if (n == 1) {
return 1;
}
return n * factorial(n - 1);
}
console.log(factorial(6));
//Output: 720
// Simple arrow function solution
var factorial = n => (n <= 0) ? 1: n * factorial(n - 1);
function factorialize(num) {
var factode = 1;
for(var i = num; i > 0; i--) {
factode *= i;
}
return factode;
}
factorialize(5);
math.factorial(5)
function factorialize(num) {
if(num < 2) return 1;
return num *= factorialize(num - 1);
}
const factorial = n => n <= 1 ? 1 : n * factorial(n - 1);
// Examples
factorial(2); // 2
factorial(3); // 6
function factorial(n) {
return (n + 1) * (n / 2);
}
function fact(N){
if(N <= 1){
return "1";
}
else
{
return N * fact(N-1);
}
}
fact(5);
var factorial = 1;
function myfact(fact) {
for (let i = 1; i <= 5; i++) {
factorial = factorial * i;
}
return factorial;
}
console.log(myfact(factorial))
// Output: 120