Here is a javascript solution
function nthPrime(n) { let primes = [2]; let higherDivisorLimit; let isPrime; for(let i = 3; primes.length < n; i+=2) { higherDivisorLimit = Math.sqrt(i) + 1; isPrime = true; for(let j = 0; primes[j] < higherDivisorLimit; j++) { if(i % primes[j] === 0) { isPrime = false; break; } } if(isPrime) primes.push(i); } return primes[primes.length - 1]; } console.log(nthPrime(10001));
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Here is a javascript solution