Created
October 3, 2018 11:45
-
-
Save e-mihaylin/9f54f545bff70e6f8244f4e07dd35310 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thankyou