Answers for "Calculate a factorial Javascript"

19

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
0

javascript factorial stack

function factorial(n) {
    let s = new Stack();
    while (n>1){
        s.push(n--);
    }
    let product = 1;
    while (s.length() > 0) {
        product *= s.pop();
    }
    return product;
}
Posted by: Guest on February-23-2021

Code answers related to "Calculate a factorial Javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language