“JavaScript trouve factoriel” Réponses codées

factoriel JavaScript

function factorial(n) {
  if (n < 0) return;
  if (n < 2) return 1;
  return n * factorial(n - 1);
}
TC5550

javascript factoriel

// Simple arrow function solution
var factorial = n => (n <= 0) ? 1: n * factorial(n - 1);
juliocorradi

Fonction JavaScript factorielle

function factorialize(num) {
  if(num < 2) return 1;
  return num *= factorialize(num - 1);
}
Tiger King

factoriel javascript d'un nombre

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

// Examples
factorial(2);   // 2
factorial(3);   // 6
Batman

JavaScript trouve factoriel

// program to find the factorial of a number
function factorial(x) {

    // if number is 0
    if (x === 0) {
        return 1;
    }

    // if number is positive
    else {
        return x * factorial(x - 1);
    }
}
const num = 3;
// calling factorial() if num is non-negative
if (num > 0) {
    let result = factorial(num);
    console.log(`The factorial of ${num} is ${result}`);
}
SAMER SAEID

Réponses similaires à “JavaScript trouve factoriel”

Parcourir les réponses de code populaires par langue

Parcourir d'autres langages de code