Created
August 15, 2018 13:13
-
-
Save agniswarm/b505bfcfd72c8be0b3bf43233ff24470 to your computer and use it in GitHub Desktop.
Prime Number
This file contains 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
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