Created
December 13, 2009 03:37
-
-
Save remy/255244 to your computer and use it in GitHub Desktop.
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
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