Last active
May 8, 2019 09:41
-
-
Save habibimustafa/6f805ee14f8021d9b57f166830f0e426 to your computer and use it in GitHub Desktop.
Javascript Find Prime Factor and The Largest
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
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); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output: