Skip to content

Instantly share code, notes, and snippets.

@birchb
Last active January 1, 2019 22:11
Show Gist options
  • Save birchb/c10903015d39f43f77648719c3df6c40 to your computer and use it in GitHub Desktop.
Save birchb/c10903015d39f43f77648719c3df6c40 to your computer and use it in GitHub Desktop.
let primes = [ ]
const findNextPrime = (primeArray) => {
let foundPrime = false
for(np = 2; !foundPrime; np++) {
let isPrime = true
while(isPrime){
for(p = 0; p < primeArray.length; p++) {
if (np % primes[p] == 0) {
isPrime = false
break
}
}
if (isPrime == 1) {
foundPrime = 1
return np
}
}
}
}
let newPrime = findNextPrime(primes)
console.log('newPrime: ', newPrime);
primes.push(newPrime)
console.log(primes)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment