Skip to content

Instantly share code, notes, and snippets.

@vitkarpov
Created July 11, 2018 16:45
Show Gist options
  • Save vitkarpov/9f6df2638a060a89dafabf5dc724ea7c to your computer and use it in GitHub Desktop.
Save vitkarpov/9f6df2638a060a89dafabf5dc724ea7c to your computer and use it in GitHub Desktop.
Extra Long Factorial
function mult(a, b) {
let carry = 0;
for (let i = 0; i < a.length || carry > 0; i++) {
if (i === a.length) {
a.push(0);
}
const curr = carry + a[i] * b;
a[i] = curr % 10;
carry = Math.floor(curr / 10);
}
}
// mult in loop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment