Skip to content

Instantly share code, notes, and snippets.

@jonathanmarvens
Last active July 10, 2021 18:32
Show Gist options
  • Save jonathanmarvens/7206278 to your computer and use it in GitHub Desktop.
Save jonathanmarvens/7206278 to your computer and use it in GitHub Desktop.
var primeFactorization = function primeFactorization(number, result) {
var result = (result || []);
var root = Math.sqrt(number);
var x = 2;
if (number % x) {
x = 3;
while ((number % x) && ((x = (x + 2)) < root)) {}
}
x = (x <= root) ? x : number;
result.push(x);
return (x === number) ? result : primeFactorization((number / x), result);
};
Math.primeFactorization = primeFactorization;
@antoniobuconjic
Copy link

Thanks! Was looking for this through the web for a long time

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