Created
April 6, 2019 15:54
-
-
Save rosd89/1859f481b94d0c1136078892a8f40bad 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 prime1 = end => { | |
const prime = [], num = []; | |
let curr = 2, i = curr; | |
while(i <= end) num.push(i++); | |
while(num.length){ | |
prime.push(curr = num.shift()); | |
i = num.length; | |
while(i--) if(num[i] % curr == 0) num.splice(i, 1); | |
if(curr * curr > num[num.length - 1]) break; | |
} | |
return prime.concat(num); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment