Array.range = (start, stop, step=1) => {
let A = [start];
while(start+step <= stop){
A = [...A, start+=step];
}
return A;
}
function sieveOfEratosthenes(num) {
let primes = Array.range(3,num,2).filter((val) =>{
for(i=3; i <= Math.sqrt(val); i+=2) {
if(val % i === 0 ){return false;}
}
return val > 1;
});
return [2,...primes];
}
console.log(sieveOfEratosthenes(200));
Created
December 22, 2017 14:58
-
-
Save carl-parrish/485347a53d597bca22080f909844e697 to your computer and use it in GitHub Desktop.
Sieve of Eratosthenes
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment