Skip to content

Instantly share code, notes, and snippets.

@davidhellsing
Created February 20, 2012 19:16
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 davidhellsing/1870832 to your computer and use it in GitHub Desktop.
Save davidhellsing/1870832 to your computer and use it in GitHub Desktop.
Prime number tester
// Test if a number is Prime using a simple regex.
// Demo: http://jsfiddle.net/rJhpq/
function prime(n) {
return !/^1?$|^(11+?)\1+$/.test((function(n){s='';while(n--)s+='1';return s;}(n)));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment