Created
September 16, 2015 10:05
-
-
Save dlidstrom/a88d9f7c23514a4dfe82 to your computer and use it in GitHub Desktop.
Primality checking using regular expression.
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
// 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