Skip to content

Instantly share code, notes, and snippets.

@AdrianSkar
Last active February 19, 2018 20:28
Show Gist options
  • Save AdrianSkar/fec95ba96baf4725426b4ddbcfcaf0e9 to your computer and use it in GitHub Desktop.
Save AdrianSkar/fec95ba96baf4725426b4ddbcfcaf0e9 to your computer and use it in GitHub Desktop.
// Using a for loop and reduce(); not the simplest solution but succesful first attempt.
function factorialize(num) {
if (num == 0){
return 1;
}
var arr = [];
for (i=num; i>0; i--){
arr.push(i);
}
return arr.reduce(function(a,b){
return a * b;
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment