Skip to content

Instantly share code, notes, and snippets.

@Prosen-Ghosh
Created August 30, 2017 10:25
Show Gist options
  • Save Prosen-Ghosh/6863a606d352de950a959c8ecb6b3b23 to your computer and use it in GitHub Desktop.
Save Prosen-Ghosh/6863a606d352de950a959c8ecb6b3b23 to your computer and use it in GitHub Desktop.
It will generate 6,64,579 prime number.
function prime(n){
let arr = new Array(n).fill(true);
arr[0] = arr[1] = false;
let range = Math.sqrt(n);
for(let i = 2; i <= n; i++){
if(arr[i] === true){
for(let j = i*2; j <= n; j+= i){
arr[j] = false;
}
}
}
return arr;
}
prime(10000001).map(function(c,ind){
if(c)return ind;
}).filter((n) => n != undefined)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment