Last active
October 21, 2016 02:21
-
-
Save chul-hyun/a29ec13aa5053e61f7c97291a534d907 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 getPrime(max){ | |
let sieve = _.fill(Array(max), true); | |
let _max = Math.floor(Math.sqrt(max)); | |
sieve[0] = false; | |
sieve[1] = false; | |
for(let i = 2 ; i <= _max ; i++){ | |
if(sieve[i]){ | |
for(let j = i * 2 ; j <= max ; j += i){ | |
sieve[j] = false; | |
} | |
} | |
} | |
let result = []; | |
sieve.forEach((check, index, arr)=>((check) && result.push(index))); | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment