Skip to content

Instantly share code, notes, and snippets.

@wvl
Created April 7, 2011 22:51
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 wvl/908957 to your computer and use it in GitHub Desktop.
Save wvl/908957 to your computer and use it in GitHub Desktop.
synchronous, so make it so -- node primes
var isPrime2 = function(n) {
var root = Math.sqrt(n);
for (var i=3; i<=root; i += 2) {
if (n%i == 0) {
return false;
}
}
return true;
}
var primes2 = function (primesn) {
results = [];
for (var i=3; i<primesn; i+=2) {
if (isPrime2(i)) {
results.push(i);
}
}
return results;
}
primes2(process.argv[2]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment