Skip to content

Instantly share code, notes, and snippets.

@e-mihaylin
Created October 3, 2018 11:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save e-mihaylin/9f54f545bff70e6f8244f4e07dd35310 to your computer and use it in GitHub Desktop.
Save e-mihaylin/9f54f545bff70e6f8244f4e07dd35310 to your computer and use it in GitHub Desktop.
const factorial = n => {
if (!n) return '1'
let i, next, carret;
const result = n.toString().split``.reverse().map(Number);
while (--n) {
i = carret = 0;
while ((next = result[i++]) !== undefined || carret) {
carret += n * (next || 0);
result[i - 1] = carret % 10;
carret = parseInt(carret / 10);
}
}
return result.reverse().join``;
}
//https://www.codewars.com/kata/large-factorials/javascript
@codehilltop95
Copy link

thankyou

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment