Last active
July 10, 2021 18:32
-
-
Save jonathanmarvens/7206278 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
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; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks! Was looking for this through the web for a long time