Skip to content

Instantly share code, notes, and snippets.

  • Save anonymous/e045cc237ce7d175b164 to your computer and use it in GitHub Desktop.
Save anonymous/e045cc237ce7d175b164 to your computer and use it in GitHub Desktop.
http://www.freecodecamp.com/rjmccallumbigl 's solution for Bonfire: Factorialize a Number
// Bonfire: Factorialize a Number
// Author: @rjmccallumbigl
// Challenge: http://www.freecodecamp.com/challenges/bonfire-factorialize-a-number?solution=function%20factorialize(num)%20%7B%0A%20%20%0A%20%20var%20num2%20%3D%200%3B%0A%20%20var%20i%20%3D%201%3B%0A%20%20%0A%20%20%20%20if%20(num%20%3D%3D%3D%200)%7B%0A%20%20%20%20%20%20%0A%20%20%20%20%20%20return%201%3B%0A%20%20%20%20%20%20%0A%20%20%20%20%7D%0A%0A%20%20%0A%20%20while%20(num%20%3E%202)%20%7B%0A%20%20%20%20%0A%20%20%20%20i%20*%3D%20num%3B%0A%20%20%20%20%20%20%20%20%0A%20%20%20%20num--%3B%0A%20%20%20%20%0A%20%20%20%20%7D%0A%20%20%0A%20%20i%20*%3D%202%3B%0A%20%20%0A%20%20%20%20return%20i%3B%0A%20%20%0A%20%20%2F%2Freturn%20num%3B%0A%7D%0A%0Afactorialize(5)%3B%0A
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function factorialize(num) {
var num2 = 0;
var i = 1;
if (num === 0){
return 1;
}
while (num > 2) {
i *= num;
num--;
}
i *= 2;
return i;
//return num;
}
factorialize(5);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment