Skip to content

Instantly share code, notes, and snippets.

@wdiasvargas
Created June 18, 2017 04:41
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 wdiasvargas/064bcea6ddf3120b530285acf549e4de to your computer and use it in GitHub Desktop.
Save wdiasvargas/064bcea6ddf3120b530285acf549e4de to your computer and use it in GitHub Desktop.
function isPrime(n) {
if (n == 2 || n == 3 || n == 5 || n == 7) {
return true;
} else if ((n < 2) || (n % 2 == 0)) {
return false;
} else {
for (var i = 3; i <= Math.sqrt(n); i += 2) {
if (n % i == 0)
return false;
}
return true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment