0
0
GGGiovanny Gongora
Generates primes up to a given number, using the Sieve of Eratosthenes.
const primes = (num: number) => {
let arr: Array<number> = Array.from({ length: num - 1 }).map((x, i) => i + 2),
sqroot: number = Math.floor(Math.sqrt(num)),
numsTillSqroot: Array<number> = Array.from({ length: sqroot - 1 }).map((x, i) => i + 2);
numsTillSqroot.forEach(x => (arr = arr.filter(y => y % x !== 0 || y === x)));
return arr;
};