0
const factorial = (n) => {
  if (n === 0) return 1;
  return factorial(n - 1) * n;
};
console.log(factorial(5)); //Output: 120


const factorial = (n) => {
  if (n === 0) return 1;
  return factorial(--n) * n;
};
console.log(factorial(5)); //Output: 0

What the difference? Why in the second example i get 0.

Evgeniy
  • 1
  • 1

0 Answers0