Last active
April 6, 2019 18:57
-
-
Save rosd89/ab8e480a7e9a7f83bd313ea0b2b908c9 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
const prime4 = end =>{ | |
if(end < 2) return []; | |
const num = [2]; | |
for(let i = 3; i <= end; i += 2) num.push(i); | |
for(let i = 1, j = num.length, curr; i < j; i++){ | |
if(curr = num[i]){ | |
const min = curr * curr; | |
if(end < min) break; | |
for(let k = (min - 1) / 2; k < j; k += curr) { | |
if(num[k] != 0 && num[k] % curr == 0) num[k] = 0; | |
} | |
} | |
} | |
return num.filter(v => v); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment