Skip to content

Instantly share code, notes, and snippets.

@isabellachen
Last active March 2, 2018 14:46
Show Gist options
  • Save isabellachen/9cbb6e434b3762a96cd5ff37d5978db4 to your computer and use it in GitHub Desktop.
Save isabellachen/9cbb6e434b3762a96cd5ff37d5978db4 to your computer and use it in GitHub Desktop.
factorial function in JS two ways
function factorial (n) {
let product = 1
for (let i=n; i>0; i--) {
product = product * i
}
return product
}
console.log(factorial(5))
function factorialRecursion (n) {
if (n===0) {
return 1
} else {
return n * factorialRecursion(n-1)
}
}
console.log(factorialRecursion(5))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment