function Filter(number, filter) {
    this.number = number;
    this.filter = filter;
}
Filter.prototype.accept = function(n) {
  var filter = this;
  for (;;) {
      if (n % filter.number === 0) {
          return false;
      }
      filter = filter.filter;
      if (filter === null) {
          break;
      }
  }
  return true;
};

function Primes(natural) {
    this.natural = natural;
    this.at = 0;
    this.filter = null;
}
Primes.prototype.next = function() {
    for (;;) {
        var n = this.natural[this.at++];
        if (this.filter === null || this.filter.accept(n)) {
            this.filter = new Filter(n, this.filter);
            return n;
        }
    }
};

function measure(prntCnt, upto) {
    var natural = Interop.import('Natural');
    var primes = new Primes(Interop.execute(natural));
    
    var log = typeof console !== 'undefined' ? console.log : print;
    var start = new Date().getTime();
    var cnt = 0;
    var res = -1;
    for (;;) {
        res = primes.next();
        cnt++;
        if (cnt % prntCnt === 0) {
            log("Computed " + cnt + " primes in " + (new Date().getTime() - start) + " ms. Last one is " + res);
        }
        if (upto && cnt >= upto) {
            break;
        }
    }
    return new Date().getTime() - start;
}

for (;;) {
    var log = typeof console !== 'undefined' ? console.log : print;
    log("Five thousand prime numbers in " + measure(1000, 5000) + " ms");
}

function Filter(number) {
    this.number = number;
    this.next = null;
    this.last = this;
}
Filter.prototype.acceptAndAdd = function(n) {
  var filter = this;
  var sqrt = Math.sqrt(n);
  for (;;) {
      if (n % filter.number === 0) {
          return false;
      }
      if (filter.number > sqrt) {
          break;
      }
      filter = filter.next;
  }
  var newFilter = new Filter(n);
  this.last.next = newFilter;
  this.last = newFilter;
  return true;
};

function Primes(natural) {
    this.natural = natural;
    this.at = 0;
    this.filter = null;
}
Primes.prototype.next = function() {
    for (;;) {
        var n = this.natural[this.at++];
        if (this.filter === null) {
            this.filter = new Filter(n);
            return n;
        }
        if (this.filter.acceptAndAdd(n)) {
            return n;
        }
    }
};

function measure(prntCnt, upto) {
    var natural = Interop.import('Natural');
    var primes = new Primes(Interop.execute(natural));

    var log = typeof console !== 'undefined' ? console.log : print;
    var start = new Date().getTime();
    var cnt = 0;
    var res = -1;
    for (;;) {
        res = primes.next();
        cnt++;
        if (cnt % prntCnt === 0) {
            log("Computed " + cnt + " primes in " + (new Date().getTime() - start) + " ms. Last one is " + res);
            prntCnt *= 2;
        }
        if (upto && cnt >= upto) {
            break;
        }
    }
    return new Date().getTime() - start;
}

for (;;) {
    var log = typeof console !== 'undefined' ? console.log : print;
    log("Hundred thousand prime numbers in " + measure(97, 100000) + " ms");
}

Modify the R+js algorithm to also count to one hundred throusand primes