Skip to content

Instantly share code, notes, and snippets.

@habibimustafa
Last active May 8, 2019 09:41
Show Gist options
  • Save habibimustafa/6f805ee14f8021d9b57f166830f0e426 to your computer and use it in GitHub Desktop.
Save habibimustafa/6f805ee14f8021d9b57f166830f0e426 to your computer and use it in GitHub Desktop.
Javascript Find Prime Factor and The Largest
var divisor = 2;
var number = 210;
let primeFactor = [];
while (number > 1) {
if (number % divisor === 0) {
number /= divisor;
if (primeFactor.indexOf(divisor) === -1) {
primeFactor.push(divisor);
}
} else {
divisor++;
}
}
console.log(divisor);
console.log(primeFactor);
@habibimustafa
Copy link
Author

habibimustafa commented May 8, 2019

Output:

7
[2, 3, 5, 7]

Prime Factor Tree

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment