Created
April 29, 2020 21:26
-
-
Save gavinsykes/7e81411bc90d26cef814e1e508ca7243 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 genMaxPrime = n => { | |
let result; | |
if (n < 1 || Number.isInteger(n)) { | |
return undefined; | |
} | |
while (!(n&1)) { | |
result = 2; | |
n >> 1; | |
} | |
for (let i = 3; i < Math.sqrt(n);i += 2) { | |
while (n % i == 0) { | |
result = i; | |
n = n / i; | |
} | |
} | |
if (n > 2) { | |
result = n; | |
} | |
return result; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment