Skip to content

Instantly share code, notes, and snippets.

@dlidstrom
Created September 16, 2015 10:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dlidstrom/a88d9f7c23514a4dfe82 to your computer and use it in GitHub Desktop.
Save dlidstrom/a88d9f7c23514a4dfe82 to your computer and use it in GitHub Desktop.
Primality checking using regular expression.
// http://rosettacode.org/wiki/Primality_by_trial_division#By_Regular_Expression
function isPrime(n) {
var e = /^1?$|^(11+?)\1+$/;
return !e.exec('1'.repeat(n));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment