Skip to content

Instantly share code, notes, and snippets.

@aMoRRoMa
Forked from ytiurin/factorial.js
Created October 22, 2019 12:53
Show Gist options
  • Save aMoRRoMa/90d0b4845e124dd9a1f8101b30262f08 to your computer and use it in GitHub Desktop.
Save aMoRRoMa/90d0b4845e124dd9a1f8101b30262f08 to your computer and use it in GitHub Desktop.
Calculate extra large factorial
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