Skip to content

Instantly share code, notes, and snippets.

@gavinsykes
Created April 29, 2020 21:26
Show Gist options
  • Save gavinsykes/7e81411bc90d26cef814e1e508ca7243 to your computer and use it in GitHub Desktop.
Save gavinsykes/7e81411bc90d26cef814e1e508ca7243 to your computer and use it in GitHub Desktop.
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