Skip to content

Instantly share code, notes, and snippets.

@remy
Created December 13, 2009 03:37
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 remy/255244 to your computer and use it in GitHub Desktop.
Save remy/255244 to your computer and use it in GitHub Desktop.
function isPrime( num ) {
if ( isPrime.cache[ num ] != null )
return isPrime.cache[ num ];
// everything but 1 can be prime
var prime = num != 1;
for ( var i = 2; i < num; i++ ) {
if ( num % i == 0 ) {
prime = false;
break;
}
}
isPrime.cache[ num ] = prime
return prime;
}
isPrime.cache = {};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment