Skip to content

Instantly share code, notes, and snippets.

@demoive
Last active February 9, 2025 16:56
Show Gist options
  • Save demoive/5753255 to your computer and use it in GitHub Desktop.
Save demoive/5753255 to your computer and use it in GitHub Desktop.
function PrimeNumberGenerator() {
this.indx = 2;
}
PrimeNumberGenerator.prototype.next = function () {
var counter = 2;
while (counter < this.indx) {
if (this.indx % counter++ === 0) {
counter = 2;
this.indx++;
}
}
return this.indx++;
}
@demoive
Copy link
Author

demoive commented Jun 10, 2013

var myPrimes = new PrimeNumberGenerator();

myPrimes.next(); // 2
myPrimes.next(); // 3
myPrimes.next(); // 5
myPrimes.next(); // 7
myPrimes.next(); // 11
myPrimes.next(); // 13
// ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment