Skip to content

Instantly share code, notes, and snippets.

@rosd89
Created April 6, 2019 15:54
Show Gist options
  • Save rosd89/1859f481b94d0c1136078892a8f40bad to your computer and use it in GitHub Desktop.
Save rosd89/1859f481b94d0c1136078892a8f40bad to your computer and use it in GitHub Desktop.
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