1
2
3
4
5
6
7
8
9
10
11
12
13
14
t = TrafficLight(); b = Button(); es = [];
b.onclick(function () {
t.red(); es.push(now());
if (es.length == 6) report(); else start();
});
start = function () {setTimeout(go, Math.random() * 3000)}
go = function () {t.green(); es.push(-now())};
div = function (a, b) {return Math.floor(a/b)};
report = function () {
var ts = es.filter(not(pos)).zip(es.filter(pos), plus);
print("Avg: " + div(ts.reduce(plus,0),ts.length) + "ms");
print("Max: " + ts.reduce(max, 0) + "ms");
};
start(); "Ready...";