-
-
Save aMoRRoMa/90d0b4845e124dd9a1f8101b30262f08 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('') | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment