Skip to content
GitHub no longer supports this web browser. Learn more about the browsers we support.
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time. Cannot retrieve contributors at this time
29 lines (24 sloc) 490 Bytes
let primes = []
function isPrime(x) {
for (let z = 0; primes[z] <= Math.sqrt(x); z++) {
if (x % primes[z] === 0) {
return false
}
}
return true
}
function nthPrime(n) {
let primeCounter = 1 //skip 2
let y = 3
while (primes.length < n) {
if (isPrime(y)) {
primes.push(y)
primeCounter++
}
if (primeCounter == n) {
return y
} else {
y +=2
}
}
}
You can’t perform that action at this time.