Skip to content

Instantly share code, notes, and snippets.

@MuddyBootsCode
Created April 26, 2022 18:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MuddyBootsCode/b8e850fb3bde2fbffd3718517cddeea3 to your computer and use it in GitHub Desktop.
Save MuddyBootsCode/b8e850fb3bde2fbffd3718517cddeea3 to your computer and use it in GitHub Desktop.
function largestPrimeFactor(number) {
let divisor, largestDivisor = 2;
while (number % 2 === 0){
number = number / divisor;
}
divisor = 3;
while (number > 1){
while(number % divisor === 0){
number = number/divisor;
largestDivisor = divisor;
}
divisor += 2;
}
return largestDivisor;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment