Handle undefineds

This commit is contained in:
b 2021-07-19 13:35:19 -07:00
parent 9b2e55f3b4
commit fd12f398bb
2 changed files with 32 additions and 5 deletions

View file

@ -233,6 +233,33 @@ class ExprField {
function compareLexico(ia, keysA, ib, keysB) { function compareLexico(ia, keysA, ib, keysB) {
for (let i = 0; i < keysA.length; i++) { // assuming keysA and keysB are the same length for (let i = 0; i < keysA.length; i++) { // assuming keysA and keysB are the same length
let aKey = keysA[i], bKey = keysB[i]; let aKey = keysA[i], bKey = keysB[i];
if (typeof aKey === 'undefined') {
switch (typeof bKey) {
case 'string':
aKey = "";
break;
case 'number':
aKey = 0;
break;
case 'undefined':
return 0;
default:
throw new Error(`Incomparable type ${typeof bKey}`);
}
}
else if (typeof(bKey) === 'undefined') {
switch (typeof aKey) {
case 'string':
bKey = "";
break;
case 'number':
bKey = 0;
break;
default:
throw new Error(`Incomparable type ${typeof aKey}`);
}
}
if (typeof aKey !== typeof bKey) throw new Error(`Incomparable types ${typeof aKey} and ${typeof bKey}`); // can this even happen? if (typeof aKey !== typeof bKey) throw new Error(`Incomparable types ${typeof aKey} and ${typeof bKey}`); // can this even happen?
switch (typeof aKey) { switch (typeof aKey) {
case 'string': case 'string':

View file

@ -58,11 +58,11 @@
"mr": 4, "mr": 4,
"xpb": 100, "xpb": 100,
"lb": 100, "lb": 100,
"str": 21, "str": 15,
"dex": 21, "dex": 15,
"int": 21, "int": 15,
"agi": 21, "agi": 15,
"def": 21, "def": 15,
"hpBonus": 6800, "hpBonus": 6800,
"spRaw1": -1, "spRaw1": -1,
"spRaw2": -1, "spRaw2": -1,