Skip to content

Instantly share code, notes, and snippets.

@chee
Created May 6, 2014 21:01
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 chee/fcbf4e2cd66d65341c64 to your computer and use it in GitHub Desktop.
Save chee/fcbf4e2cd66d65341c64 to your computer and use it in GitHub Desktop.
function getPrimes(max) {
return Array.apply(null, {length: max + 1}).map(function(){}.call, Number).filter(function(n) {
if (n < 2) return false;
for (var i = 2; i <= Math.sqrt(n); i++) {
if (n % i == 0) return false;
}
return true;
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment