Skip to content

Instantly share code, notes, and snippets.

@javierfurus
Created November 21, 2015 14:01
Show Gist options
  • Save javierfurus/f07cf588ae1a271a5581 to your computer and use it in GitHub Desktop.
Save javierfurus/f07cf588ae1a271a5581 to your computer and use it in GitHub Desktop.
My solution for "Bonfire: Factorialize a number"
// Bonfire: Factorialize a Number
// Author: @javierfurus
// Challenge: http://www.freecodecamp.com/challenges/bonfire-factorialize-a-number
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function factorialize(num) {
var factorArray = [];
for (var i=1; i <=num; i++ ) {
factorArray.push(i);
}
if (num > 0)
return factorArray.reduce(function(a,b) {
return a*b;
});
else {
return 1;
}
}
factorialize(20);
@javierfurus
Copy link
Author

Tell me if something if wrong with it! I know it is fairly different from the actual solution, but it seems to me that it gives you the same results.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment