Last active
April 6, 2019 18:45
-
-
Save rosd89/d3aa8268157d7a11e6211a18917aabf3 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 prime3 = end =>{ | |
if(end < 2) return []; | |
const num = [2]; | |
for(let i = 3; i <= end; i += 2) num.push(i); | |
for(let k = 1; k < num.length; k++){ | |
let curr = num[k], min = curr * curr, i = num.length; | |
if(num[i - 1] < min) break; | |
while(i--){ | |
if(num[i] < min) break; | |
if(num[i] % curr == 0) num.splice(i, 1); | |
} | |
} | |
return num; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment