Category Archives: javascript prime number function

Generating n prime numbers in JavaScript

/** * Prime number * parameter n is an integer * Generate n prime numbers */ var primeList=[2]; //seed function prime(n) { n += 1; for (var k = 0; k < primeList.length; k++) { if((n%primeList[k])==0) return prime(n); } primeList.push(n); … Continue reading

Posted in algorithms, javascript prime number function, prime number, prime number function | Leave a comment