Skip to content

Instantly share code, notes, and snippets.

@greemwahr
Created November 14, 2015 14:57
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 greemwahr/ba8e4f289927dd59c6aa to your computer and use it in GitHub Desktop.
Save greemwahr/ba8e4f289927dd59c6aa to your computer and use it in GitHub Desktop.
function factorialize(num) {
factorialArr = [];
if (num === 0) {
factorialArr = [1];
} else {
for (i = 1; i < num + 1; i++) {
factorialArr.push(i);
}
}
var factorial = 0;
factorialArr.reduce(function(previousValue, currentValue) {
return factorial = previousValue * currentValue;
}, 1);
return factorial;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment