-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwh1-2-WRONG.js
30 lines (30 loc) · 952 Bytes
/
wh1-2-WRONG.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
(function() {
// build an array with numbers 1 ... 100
var p = new Array(101);
var i;
for( i = 0; i <= 100; i++ ) {
p[i] = i;
};
// replace non-primes with zeros
p[1] = 0;
var d; // divisor
for( d = 2; d < 11; d++ ) { // the divisor range
if( p[d] !== 0 ) { // skip non-prime divisors
for( i = d; i < 101; i+=d ) { // check all d's multiples
if(( i % d ) === 0 ) { // if divisible
if( i !== d ) { // and not the divisor itself
p[i] = 0; // it is not a prime
};
};
};
};
};
// print the list
var theList = '';
for( i = 0; i <= 100; i++ ) {
if( p[i] !== 0 ) {
theList += ( ',' + p[i] );
};
};
console.log( theList.substring(1) );
})();