20 lines
525 B
JavaScript
20 lines
525 B
JavaScript
function primeFactorsTo(max)
|
|
{
|
|
var store = [], i, j, primes = [];
|
|
for (i = 2; i <= max; ++i)
|
|
{
|
|
if (!store [i])
|
|
{
|
|
primes.push(i);
|
|
for (j = i << 1; j <= max; j += i)
|
|
{
|
|
store[j] = true;
|
|
}
|
|
}
|
|
}
|
|
return primes;
|
|
}
|
|
|
|
console.log(primeFactorsTo(5));
|
|
|
|
console.log(primeFactorsTo(15));
|