This commit is contained in:
newt 2024-10-09 18:02:35 +01:00
parent 570a809c93
commit fe5ce90cdf

View file

@ -0,0 +1,21 @@
const isPrime = (number: number) => {
for (var i = 2; i < number; i++) {
if (number % i === 0) return false;
}
return true;
};
const nthPrime = (n: number) => {
const primes: number[] = [];
let number = 2;
while (n > primes.length) {
if (isPrime(number)) primes.push(number);
number++;
}
return primes[n - 1];
};
console.log(nthPrime(10001));