Skip to content

Instantly share code, notes, and snippets.

@paulohfev
Created April 14, 2025 14:24
Show Gist options
  • Select an option

  • Save paulohfev/c95a1cfb11b5b46aa9a9f5552da048b3 to your computer and use it in GitHub Desktop.

Select an option

Save paulohfev/c95a1cfb11b5b46aa9a9f5552da048b3 to your computer and use it in GitHub Desktop.
Calculate factorial with recursion
// Calculate factorial via recursion
const calculateFactorial = (num) => {
if (num === 1) {
return 1
} else {
return num * calculateFactorial(num - 1)
}
}
// console.log('3', calculateFactorial(3))
// console.log('5', calculateFactorial(5))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment