Created
November 21, 2015 14:01
-
-
Save javierfurus/f07cf588ae1a271a5581 to your computer and use it in GitHub Desktop.
My solution for "Bonfire: Factorialize a number"
This file contains 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
// 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); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.