Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created October 4, 2019 15:42
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 parzibyte/afe52fe85d44dca5a9f72003652ace03 to your computer and use it in GitHub Desktop.
Save parzibyte/afe52fe85d44dca5a9f72003652ace03 to your computer and use it in GitHub Desktop.
/**
* Determinar si número es primo en JavaScript
*
* https://parzibyte.me/blog
*/
const esPrimo = numero => {
// Casos especiales
if (numero == 0 || numero == 1 || numero == 4) return false;
for (let x = 2; x < numero / 2; x++) {
if (numero % x == 0) return false;
}
// Si no se pudo dividir por ninguno de los de arriba, sí es primo
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment