Answers for "how to make a factorial function in javascript"

16

javascript factorial

function factorial(n) {
  if (n < 0) return;
  if (n < 2) return 1;
  return n * factorial(n - 1);
}
Posted by: Guest on May-24-2020
1

javascript factorial

function factorialize(num) {
  if (num === 0 || num === 1)
    return 1;
  for (var i = num - 1; i >= 1; i--) {
    num *= i;
  }
  return num;
}
factorialize(5);
Posted by: Guest on November-25-2019
1

how to make a factorial function in javascript

function factorialize(num) {
  var result = num;
  if (num === 0 || num === 1) 
    return 1; 
  while (num > 1) { 
    num--;
    result *= num;
  }
  return result;
}
Posted by: Guest on March-22-2020
1

factorial javascript

// Simple arrow function solution
var factorial = n => (n <= 0) ? 1: n * factorial(n - 1);
Posted by: Guest on June-29-2020
0

factorial function javascript

function factorial(n) {
        if (n > 1) {
            return n * factorial(n - 1);
        }
        return 1;
    }
Posted by: Guest on December-30-2020
1

javascript factorial of a number

const factorial = n => n <= 1 ? 1 : n * factorial(n - 1);

// Examples
factorial(2);   // 2
factorial(3);   // 6
Posted by: Guest on July-03-2020

Code answers related to "how to make a factorial function in javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language