Last active
February 25, 2023 09:54
-
-
Save ShaakhDev/e1c399bcd08c7130d588ed6d2d987a34 to your computer and use it in GitHub Desktop.
Logging all prime factors of given number
This file contains 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
function primeFactors(n){ | |
while(n % 2 == 0){ | |
console.log(2); | |
n = n / 2 | |
}; | |
for(var i = 3; i * i <= n; i = i + 2){ | |
while(n % 2 == 0){ | |
console.log(n); | |
n = n / i; | |
} | |
} | |
if(n > 2) console.log(n); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
sonni tub ko'paytuvchilarga ajratish