-
-
Save anonymous/589b2e36dba170579df6 to your computer and use it in GitHub Desktop.
http://www.freecodecamp.com/v3rse 's solution for Bonfire: Factorialize a Number
This file contains hidden or 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: @v3rse | |
// Challenge: http://www.freecodecamp.com/challenges/bonfire-factorialize-a-number?solution=function%20factorialize(num)%20%7B%0A%20%20if(num%20%3D%3D%3D%200)%7B%0A%20%20%20%20return%201%3B%0A%20%20%7D%0A%20%20for(var%20i%3Dnum-1%3B%20i%20%3E%200%3B%20i--)%7B%0A%20%20%20%20console.log(num%2B%22x%22%2Bi)%3B%0A%20%20%20%20num%3Dnum*i%3B%0A%20%20%7D%0A%20%20return%20num%3B%0A%7D%0A%0Afactorialize(5)%3B%0A | |
// Learn to Code at Free Code Camp (www.freecodecamp.com) | |
function factorialize(num) { | |
if(num === 0){ | |
return 1; | |
} | |
for(var i=num-1; i > 0; i--){ | |
console.log(num+"x"+i); | |
num=num*i; | |
} | |
return num; | |
} | |
factorialize(5); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Factorial function without recursion.