diff --git a/JS/07.10001st_prime/10001st_prime.js b/JS/07.10001st_prime/10001st_prime.js new file mode 100644 index 0000000..15c69b0 --- /dev/null +++ b/JS/07.10001st_prime/10001st_prime.js @@ -0,0 +1,36 @@ +const MAX_NUM = 1000007; + +function sieveOfEratosthenes(k) { + var visited = new Array(MAX_NUM); + + var result = -1; + var countOfPrimes = 0; + + var found = false; + var j; var i = 2; + while(i < MAX_NUM && !found) { + if(!visited[i]) { + countOfPrimes++; + + if(countOfPrimes == k) { + result = i; + found = true; + } else { + j = 2; + + while(j * i < MAX_NUM) { + visited[j*i] = true; + j++; + } + } + } + i++; + } + + return result; +} + + +(function main() { + console.log(sieveOfEratosthenes(10001)); +})()