Simplify dictTermsSort

This commit is contained in:
toasted-nutbread 2019-11-04 19:53:25 -05:00
parent fe82913991
commit ae10bb7096

View File

@ -55,39 +55,23 @@ function dictRowsSort(rows, options) {
function dictTermsSort(definitions, dictionaries=null) { function dictTermsSort(definitions, dictionaries=null) {
return definitions.sort((v1, v2) => { return definitions.sort((v1, v2) => {
let i;
if (dictionaries !== null) { if (dictionaries !== null) {
const p1 = (dictionaries[v1.dictionary] || {}).priority || 0; i = (
const p2 = (dictionaries[v2.dictionary] || {}).priority || 0; ((dictionaries[v2.dictionary] || {}).priority || 0) -
if (p1 > p2) { ((dictionaries[v1.dictionary] || {}).priority || 0)
return -1; );
} else if (p1 < p2) { if (i !== 0) { return i; }
return 1;
}
} }
const sl1 = v1.source.length; i = v2.source.length - v1.source.length;
const sl2 = v2.source.length; if (i !== 0) { return i; }
if (sl1 > sl2) {
return -1;
} else if (sl1 < sl2) {
return 1;
}
const rl1 = v1.reasons.length; i = v2.reasons.length - v1.reasons.length;
const rl2 = v2.reasons.length; if (i !== 0) { return i; }
if (rl1 < rl2) {
return -1;
} else if (rl1 > rl2) {
return 1;
}
const s1 = v1.score; i = v2.score - v1.score;
const s2 = v2.score; if (i !== 0) { return i; }
if (s1 > s2) {
return -1;
} else if (s1 < s2) {
return 1;
}
return v2.expression.toString().localeCompare(v1.expression.toString()); return v2.expression.toString().localeCompare(v1.expression.toString());
}); });