Skip to content

Instantly share code, notes, and snippets.

@KargJonas
Last active April 8, 2023 15:33
Show Gist options
  • Select an option

  • Save KargJonas/0cf239711d639bb5992df533b404072b to your computer and use it in GitHub Desktop.

Select an option

Save KargJonas/0cf239711d639bb5992df533b404072b to your computer and use it in GitHub Desktop.
A rather nice way to check if a number is prime.
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