In general Sieve of Sundaram , produces primes smaller than ( 2 * x + 2 ) for a number given number x . Since we want primes smaller than MAX , we reduce MAX to half This array is used to separate numbers of the form i + j + 2 ij from others where 1 <= i <= j
let marked = Array . from ( { length : MAX / 2 + 1 } , ( _ , i ) => 0 ) ;