Here's (nearly) the best I can do with the Sieve of Erastothenes:

Improvements:Code:<script type="text/javascript"> var nums = [ ]; var primes = [2]; var MAXNUM = 500; // change this as desired // run the actual seive for ( var chk = 3; chk < MAXNUM; chk += 2 ) { if ( nums[chk] == null ) { primes.push(chk); for ( var mark = chk*3; mark < MAXNUM; mark += chk*2 ) { nums[mark] = 0; // any non-null would do } } } alert(primes); </script>

(a) no need to initialize the array

(b) only checks odd numbers

(c) only marks odd increments of a found prime

(d) doesn't bother marking a found prime

The next step: Would only save memory, not speed. And probably not even that with JavaScript coding. Have each element of the array represent an ODD number. That is, the element numbering doesn't match the numbers represented. So the array can be half the size it is now.

Aside from changing algorithms, do you see a way to improve that?