Created
October 18, 2016 12:15
-
-
Save ytiurin/d00d50ad63be75b4859670f405128d94 to your computer and use it in GitHub Desktop.
Calculate extra large factorial
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
function factorial(userInt) | |
{ | |
if(userInt===0) | |
return '1' | |
if(!userInt) | |
return '' | |
var i, nextNumber, carret, | |
result = userInt.toString().split('').reverse().map(Number) | |
while(--userInt){ | |
i = carret = 0 | |
while((nextNumber = result[i++]) !== undefined || carret) { | |
carret = (nextNumber || 0) * userInt + carret | |
result[i-1] = carret % 10 | |
carret = parseInt(carret/10) | |
} | |
} | |
return result.reverse().join('') | |
} |
Best and concise decision that I've seen so far, thank you.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
how did u do that ?care to explain?