previous

page 19

next

You may have noticed that I omitted the curly brackets { } on a couple of lines.
For example:

if (cn>0) counts[cn]++;

In fact curly brackets are only mandatory in JavaScript when it is necessary to group lines of code together.
So here's my worth function which takes full advantage of that fact.
Note particularly the if else lines.

function worth(arr) {
var counts=[];
for (var i=0; i<10; i++) counts[i]=0;
for (var i=0; i<5; i++) {
var cn=arr[i];
if (cn>0) counts[cn]++;
}
Sort(counts);
if (counts[9]==5) return 20;
if (counts[9]==4) return 12;
if (counts[9]==3) {
if (counts[8]==2) return 8; else return 5;
}
if (counts[9]==2) {
if (counts[8]==2) return 2; else return 1;
}
return 0;
}
previous
next