One-dimensional cellular automata: Difference between revisions

Content added Content deleted
(Added JavaScript)
Line 750: Line 750:


=={{header|JavaScript}}==
=={{header|JavaScript}}==
The example below expects an array of 1s or 0s, as in the example algorithm. It also adds dead cells to both ends, which aren't included in the returned next generation.
The example below expects an array of 1s or 0s, as in the example. It also adds dead cells to both ends, which aren't included in the returned next generation.


state[i-1] refers to the new cell in question, (old[i] == 1) checks if the old cell was alive.
state[i-1] refers to the new cell in question, (old[i] == 1) checks if the old cell was alive.