Skip to content

Instantly share code, notes, and snippets.

@OpenGrid
Last active December 19, 2015 00:49

Revisions

  1. OpenGrid revised this gist Jun 27, 2013. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions primes.js
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    function getPrimes(howMany) {
    var primes = [];
    var isPrime, primesCount = 0, candidate, primeIndex;
    var primes = [], isPrime, primesCount = 0, candidate, primeIndex;

    for (candidate = 2; primesCount < howMany; candidate++) {
    for(primeIndex = 0, isPrime = true;
    primeIndex < primesCount && primes[primeIndex] <= Math.sqrt(candidate) && isPrime;) {
  2. OpenGrid revised this gist Jun 27, 2013. 1 changed file with 7 additions and 9 deletions.
    16 changes: 7 additions & 9 deletions primes.js
    Original file line number Diff line number Diff line change
    @@ -3,17 +3,15 @@ function getPrimes(howMany) {
    var isPrime, primesCount = 0, candidate, primeIndex;
    for (candidate = 2; primesCount < howMany; candidate++) {
    for(primeIndex = 0, isPrime = true;
    primeIndex < primesCount && primes[primeIndex] <= Math.sqrt(candidate);
    primeIndex++) {
    if (candidate % primes[primeIndex] === 0) {
    isPrime = false;
    break;
    }
    primeIndex < primesCount && primes[primeIndex] <= Math.sqrt(candidate) && isPrime;) {

    isPrime = (candidate % primes[primeIndex++] === 0) ? false : true;
    }
    if(isPrime) {
    primes.push(candidate);
    primesCount++;
    if(isPrime === false) {
    continue;
    }
    primes[primesCount++] = candidate;

    }
    return primes;
    }
  3. OpenGrid revised this gist Jun 26, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion primes.js
    Original file line number Diff line number Diff line change
    @@ -3,7 +3,7 @@ function getPrimes(howMany) {
    var isPrime, primesCount = 0, candidate, primeIndex;
    for (candidate = 2; primesCount < howMany; candidate++) {
    for(primeIndex = 0, isPrime = true;
    primeIndex < primesCount, primes[primeIndex] <= Math.sqrt(candidate);
    primeIndex < primesCount && primes[primeIndex] <= Math.sqrt(candidate);
    primeIndex++) {
    if (candidate % primes[primeIndex] === 0) {
    isPrime = false;
  4. OpenGrid created this gist Jun 26, 2013.
    19 changes: 19 additions & 0 deletions primes.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    function getPrimes(howMany) {
    var primes = [];
    var isPrime, primesCount = 0, candidate, primeIndex;
    for (candidate = 2; primesCount < howMany; candidate++) {
    for(primeIndex = 0, isPrime = true;
    primeIndex < primesCount, primes[primeIndex] <= Math.sqrt(candidate);
    primeIndex++) {
    if (candidate % primes[primeIndex] === 0) {
    isPrime = false;
    break;
    }
    }
    if(isPrime) {
    primes.push(candidate);
    primesCount++;
    }
    }
    return primes;
    }