Skip to content

Instantly share code, notes, and snippets.

@xqft
Created September 15, 2022 00:02
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 xqft/6405ca9a67da821a00257667e8d17e4a to your computer and use it in GitHub Desktop.
Save xqft/6405ca9a67da821a00257667e8d17e4a to your computer and use it in GitHub Desktop.
Funcion isPrime()
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