offload/__test__/count-primes.worker.ts
Anton Nesterov 2d559dfb31
init
2024-10-25 23:19:39 +02:00

29 lines
427 B
TypeScript

import { handler } from "../mod.ts";
const isPrime = (n: number) => {
let result = true;
if (n <= 1) {
result = false;
} else {
for (let i = 2; i * i <= n; i++) {
if (n % i === 0) {
result = false;
break;
}
}
}
return result;
};
handler((n: number) => {
let result = 0;
for (let i = 0; i < n; i++) {
if (isPrime(i)) {
result++;
}
}
return result;
});