Last active
April 8, 2023 15:33
-
-
Save KargJonas/0cf239711d639bb5992df533b404072b to your computer and use it in GitHub Desktop.
A rather nice way to check if a number is prime.
This file contains hidden or 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) { | |
| if (n < 2) return false; | |
| let divisor = 2; | |
| while (divisor <= n / 2) { | |
| if (n % divisor === 0) return false; | |
| ++divisor; | |
| } | |
| return true; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment