Skip to content

Instantly share code, notes, and snippets.

@lostvikx
Created December 22, 2021 19:53
Show Gist options
  • Save lostvikx/cfe30054e9f811f6ab78d6ff8c0caf57 to your computer and use it in GitHub Desktop.
Save lostvikx/cfe30054e9f811f6ab78d6ff8c0caf57 to your computer and use it in GitHub Desktop.
function largestPrimeFactor(num) {
let larFac = 0;
let count = 2;
while (count * count <= num) {
if (num % count === 0) {
num /= count;
larFac = count;
} else count++;
}
if (num > larFac) larFac = num;
return larFac;
}
console.log(largestPrimeFactor(13195)); // 29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment