sajad torkamani

Here’s how to get the factorial of a number in JavaScript:

function factorial(num) {
  if (num < 0) return -1
  if (num === 0) return 1
  
  return num * factorial(num - 1)
}
Tagged: Algorithms

Leave a comment

Your email address will not be published. Required fields are marked *