Skip to content

Instantly share code, notes, and snippets.

@oleggrishechkin
Last active May 27, 2021 16:58
Show Gist options
  • Save oleggrishechkin/ce7d5c63cda786fbac60adf03f5e996f to your computer and use it in GitHub Desktop.
Save oleggrishechkin/ce7d5c63cda786fbac60adf03f5e996f to your computer and use it in GitHub Desktop.

шаблон

// написать функцию, которая считает факториал числа (необходиом использовать рекурсию)

const factorial = (n) => {
  // код
};

console.log(factorial(0)); // 1
console.log(factorial(4)); // 24

дополнительно

n! = 1 * 2 * 3 * 4 ... * n -1 * n;

0! = 1;

1! = 1;

решение

const factorial = (n) => n < 2 ? 1 : n * factorial(n - 1);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment