See "About This JavaScript Site" in JavaScript Index and Introduction.
The result should somewhat resemble that in GIF.
The principle is to write coloured divs of calculated size and position them absolutely to build the chart. The Mean (red) and Zero (blue) lines are div-border-bottoms.
Alternatively, images of colour could be positioned.
This should show the enumerable properties of an Object and their present values.
For dates :-
Possibly the best function so far; for all numbers ≥ 0 :-
John Wallis :-
See Wikipedia and discussion.
The Sieve is a classical, intrinsically fast method for listing prime numbers.
For the Estimate, look up Prime Number Theorem.
Work should be repeated as little as possible. Intermediate results required repeatedly should be determined once and referenced as required.
Poor : document.getElementById("Fred").rows = 3
document.getElementById("Fred").cols = 66
Good : f = document.getElementById("Fred")
f.rows = 3 ; f.cols = 66
Good : with (document.getElementById("Fred")) { rows = 3 ; cols = 66 }
Also, code should be repeated as little as possible; so use functions for such code, if as above will not suffice.
I've not speed-tested; but, except for light use, cached should beat iterative and recursive. It's substantially equivalent to using a lookup table, except that the table it generates is just as long as is needed, and no more.
A better example of cacheing follows.
JAD's Quiz 1995, question #14 - to determine the number of ways (49) to give change, in stated coin of the realm (50, 20, 10, 5 pence), for a given "Total" amount (£1.00).
Translated to JavaScript from Pascal program jad_9514.pas :-
The elements of "Coins" ought to be integers in strict descending order. That order was intended at design time; but now it seems to affect mainly speed when cache is used.
For £1.00 = 100p, cacheing intermediate results changed the time taken from intolerable to imperceptible in Borland Pascal on a 486dx/33.
Note the performance gain here with Cache set; allow for the resolution of timing.
This tests apparent instances of YYYY-MM-DD DoW in texts. It checks that Y-M-D is valid AD Gregorian and that DoW agrees. The year may be any number of digits, but if past about 275000 the date and DoW will not be verified. Paste the input into the textarea. See the code for details. Please do not use this page repeatedly; make a local copy.
Buttons 1 - Site check : pre-process at DOS prompt
with (mtr is MiniTrue-32)
mtr -x+ -o *.htm - "<li><tt>(\d.*)</tt>.*"
= \1\r > $X
or
mtr -x+ -o -c- *.htm - \d\d\d\d-\d\d-\d\d\s*[A-Z][a-z]{2}\W > $X
or
findstr /r [0-9]-[0-9][0-9]-[0-9][0-9] *.htm > $X
or
findstr /rn /c:"[0-9]-[0-9][0-9]-[0-9][0-9]
[a-z][a-z][a-z]\>" *.htm > $X
or otherwise (maybe SED?). Checks the first date on each line
(lines without dates are removed), and shows errors at end of line.
Button 1a shows all lines, 1b omits good ones.
Button 2 - Checks an HTML page, or anything else. Each error is reported in a confirm box, with some leading context.
In the command box, the field separator is TAB; if it is not possible to type it in, then paste or drag it.
Note that RegExps are used, and compose the commands accordingly.
Not yet working correctly.