Skip to content

Instantly share code, notes, and snippets.

@hendrikkao1
Created April 1, 2020 08:11
Show Gist options
  • Save hendrikkao1/4386ffb5d20181c3afa3095309f1ad6f to your computer and use it in GitHub Desktop.
Save hendrikkao1/4386ffb5d20181c3afa3095309f1ad6f to your computer and use it in GitHub Desktop.
Check if number is Prime or not
function isPrime(num) {
const root = Math.sqrt(num);
if (root <= 1) {
return false;
}
for (let i = 2; i <= root; i++) {
if (num % i === 0) {
return false;
}
}
return true;
}
for (let i = 0; i < 100; i++) {
console.log(i, isPrime(i));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment