Created
April 7, 2011 22:51
-
-
Save wvl/908957 to your computer and use it in GitHub Desktop.
synchronous, so make it so -- node primes
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
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