Created
April 1, 2020 08:11
-
-
Save hendrikkao1/4386ffb5d20181c3afa3095309f1ad6f to your computer and use it in GitHub Desktop.
Check if number is Prime or not
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(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