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);
}

This entry was posted in algorithms, javascript prime number function, prime number, prime number function. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *