Skip to content

Instantly share code, notes, and snippets.

@agniswarm
Created August 15, 2018 13:13
Show Gist options
  • Save agniswarm/b505bfcfd72c8be0b3bf43233ff24470 to your computer and use it in GitHub Desktop.
Save agniswarm/b505bfcfd72c8be0b3bf43233ff24470 to your computer and use it in GitHub Desktop.
Prime Number
function isPrime(n) {
let counter = 0;
if (n == 2) return true;
if (n % 2 == 0 || n == 1) return false;
for (let i = 1; i <= n / 2; i += 2) {
if (n % i == 0)
counter++;
if (counter == 2)
break;
}
if (counter == 1)
return true;
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment