Skip to content

Instantly share code, notes, and snippets.

@jgresalfi
Created September 4, 2016 20:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jgresalfi/daafbd47b3d403368ce791547b898d29 to your computer and use it in GitHub Desktop.
Save jgresalfi/daafbd47b3d403368ce791547b898d29 to your computer and use it in GitHub Desktop.
Factorial! factory.
function factorialize(num) {
var facArray = [];
if (num === 0) {
return 1;
} else {
for (var i = 1; i <= num; i++) {
facArray.push(i);
}
return facArray.reduce(function(a, b) { return a * b; });
}
}
factorialize(5);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment