Skip to content

Instantly share code, notes, and snippets.

@ytiurin
Created October 18, 2016 12:15
Show Gist options
  • Save ytiurin/d00d50ad63be75b4859670f405128d94 to your computer and use it in GitHub Desktop.
Save ytiurin/d00d50ad63be75b4859670f405128d94 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('')
}
@sempsmahad
Copy link

how did u do that ?care to explain?

@alexsanqp
Copy link

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