Created
September 15, 2022 00:02
-
-
Save xqft/6405ca9a67da821a00257667e8d17e4a to your computer and use it in GitHub Desktop.
Funcion isPrime()
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
const limite = 20000; | |
function isPrime(num) { | |
let prime = true; | |
for (let i = 2; i < (num/2 + 1); i++) | |
if (num % i === 0) { | |
prime = false; | |
break; | |
} | |
return num > 1 && prime | |
} | |
for (let i = 2; i <= limite; i++) | |
if (isPrime(i)) console.log(i); | |
// Definición: Solo es divisible entre 1 y si mism |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment