Here is an incentive to explore with:

```
var sieve = new Array(101);
var j, i = 101;
while (i-- > 2) {
sieve[i] = 1;
}
sieve[0] = 0;
sieve[1] = 0;
for (i = 2; i < 8; i++) {
j = i;
while (j + i < 101) {
j += i;
sieve[j] = 0;
}
}
for (i = 0; i < sieve.length; i++) {
if (sieve[i]) {
console.log(i);
}
}
```

The above is an elementary sieve. We start with an array that has all values set to `1`

, which casts to `true`

in a conditional. The *stack* is set to all true. We then manually set the zeroth and first elements to `0`

, since the cannot possibly be primes.

We’re only going up to primes up to 100 so we do not really need to re-add a number greater the closest prime to the square root of 100, which is 7. The numbers between 2 and 7, both inclusive, when sequenced over the distance to 100 will land on every index that is not prime. Note that we never start on the number, but number plus itself.

On a larger scale this may prove to have flaws, but on this problem, it fills the need. My thanks goes to @appylpye who some time ago explained this to me.

Update

##
Code

```
function is_prime(x) {
if (x < 2 || x % 2 === 0 && x !== 2) return false;
if (x > 2) {
for (var n = 3; n < x; n += 2) {
if (x % n === 0) return false;
}
}
return true;
}
for (var i = 0; i < 101; i++) {
if (is_prime(i)) {
console.log(i);
}
}
var sieve = new Array(101);
var j, i = 101;
while (i-- > 2) {
sieve[i] = 1;
}
sieve[0] = 0;
sieve[1] = 0;
for (i = 2; i < 8; i++) {
j = i;
while (j + i < 101) {
j += i;
sieve[j] = 0;
}
}
for (i = 0; i < sieve.length; i++) {
if (sieve[i]) {
console.log(i);
}
}
```

Speaking of primes, we know that a limited number are all we really need. In this case, 2, 3, 5, and 7.

```
var j, i = 101, p = [2, 3, 5, 7];
while (i-- > 2) {
sieve[i] = 1;
}
sieve[0] = 0;
sieve[1] = 0;
for (i = 0; i < p.length; i++) {
j = p[i];
k = j;
while (j + k < 101) {
j += k;
sieve[j] = 0;
}
}
```

Study closely and your precocious nature will reveal another puzzle. We don’t really need a separate list of primes since we are building one. How might this program traverse its own generated data for primes as it moves along? If it can be asked, it can be done.