Skip to content

Instantly share code, notes, and snippets.

@codebubb
Created November 13, 2015 20:17
Show Gist options
  • Save codebubb/022e5cf82532ab904ae0 to your computer and use it in GitHub Desktop.
Save codebubb/022e5cf82532ab904ae0 to your computer and use it in GitHub Desktop.
// Bonfire: Factorialize a Number
// Author: @codebubb
// Challenge: http://www.freecodecamp.com/challenges/bonfire-factorialize-a-number?solution=%2F%2F%20Recursive%20Factorialize%20example%0Afunction%20factorialize(num)%20%7B%0A%20%20if(num%20%3D%3D%201%20%7C%7C%20num%20%3D%3D%3D%200)%7B%0A%20%20%20%20return%201%3B%0A%20%20%7D%0A%20%20var%20result%20%3D%20factorialize(num-1)%20*%20num%3B%0A%20%20return%20result%3B%0A%7D%0A%0Afactorialize(5)%3B%0A
// Learn to Code at Free Code Camp (www.freecodecamp.com)
// Recursive Factorialize example
function factorialize(num) {
if(num == 1 || num === 0){
return 1;
}
var result = factorialize(num-1) * num;
return result;
}
factorialize(5);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment