Nth Prime

Find the nth prime number using primality testing.

Code

Algorithms
const isPrime = x => { if (x < 2) return false; for (let i = 2; i * i <= x; i++) if (x % i === 0) return false; return true; };
let count = 0, num = 1;
while (count < n) { num++; if (isPrime(num)) count++; }
return num;

Parameters

Position (1-indexed)

Browser·fetch() may be limited by CORS

More JavaScript Snippets