Last active
September 11, 2018 05:47
-
-
Save frentsel/200527aab3d5a62960f526c35aa1f13e to your computer and use it in GitHub Desktop.
Factorial (Javascript)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var factorial = function(num) { | |
return !num ? 1 : num *= factorial(num - 1); | |
} | |
// Shorter ES6 variant | |
// const factorial = num => !num ? 1 : num *= factorial(num-1); | |
alert(factorial(6)); // 720 | |
// https://jsfiddle.net/2ary59t0/157/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment