Is there a better way to write this JavaScript?
switch (l) {
//A
case '1-1-1':
case '1-1-2':
case '1-2-1':
case '2-1-1':
case '3-1-1':
obj.result = 'A';
break;
//B
case '1-2-2':
case '1-2-3':
case '2-2-2':
case '2-2-3':
case '3-2-2':
case '3-3-1':
obj.result = 'B';
break;
//C
case '1-3-2':
case '1-3-3':
case '2-3-2':
case '3-2-3':
obj.result = 'C';
break;
//D
case '3-3-2':
case '3-3-3':
obj.result = 'D';
break;
default:
obj.result = 'AA';
break;
}
The lookup table, as mentioned by Thilo in the comments:
and its usage:
I can’t say this is really any better than the
switchversion.