This commit is contained in:
newt! 2021-10-29 01:52:30 +01:00
parent fb4d83264b
commit a4b2c7dbed
No known key found for this signature in database
GPG key ID: AE59B20CEDCE087D

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));