aboutsummaryrefslogtreecommitdiff
path: root/ext/bg/js/dictionary.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-01-28 18:58:14 -0500
committertoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-02-01 21:00:27 -0500
commit1d9332cb69d76818a1f6a422ceafc3a463c48d7c (patch)
tree4ae4392b70cc00b7bb24c7d96d99a2055591d06f /ext/bg/js/dictionary.js
parent09a1214f49f89824aa7680b398fb93bc911ff6b8 (diff)
Simplify getSequencedDefinitions and dictTermsMergeBySequence
Diffstat (limited to 'ext/bg/js/dictionary.js')
-rw-r--r--ext/bg/js/dictionary.js20
1 files changed, 12 insertions, 8 deletions
diff --git a/ext/bg/js/dictionary.js b/ext/bg/js/dictionary.js
index 67128725..7d6bf7ba 100644
--- a/ext/bg/js/dictionary.js
+++ b/ext/bg/js/dictionary.js
@@ -159,11 +159,14 @@ function dictTermsGroup(definitions, dictionaries) {
}
function dictTermsMergeBySequence(definitions, mainDictionary) {
- const definitionsBySequence = {'-1': []};
+ const sequencedDefinitions = new Map();
+ const nonSequencedDefinitions = [];
for (const definition of definitions) {
- if (mainDictionary === definition.dictionary && definition.sequence >= 0) {
- if (!definitionsBySequence[definition.sequence]) {
- definitionsBySequence[definition.sequence] = {
+ const sequence = definition.sequence;
+ if (mainDictionary === definition.dictionary && sequence >= 0) {
+ sequencedDefinition = sequencedDefinitions.get(sequence);
+ if (typeof sequencedDefinition === 'undefined') {
+ sequencedDefinition = {
reasons: definition.reasons,
score: Number.MIN_SAFE_INTEGER,
expression: new Set(),
@@ -173,15 +176,16 @@ function dictTermsMergeBySequence(definitions, mainDictionary) {
dictionary: definition.dictionary,
definitions: []
};
+ sequencedDefinitions.set(sequence, sequencedDefinition);
+ } else {
+ sequencedDefinition.score = Math.max(sequencedDefinition.score, definition.score);
}
- const score = Math.max(definitionsBySequence[definition.sequence].score, definition.score);
- definitionsBySequence[definition.sequence].score = score;
} else {
- definitionsBySequence['-1'].push(definition);
+ nonSequencedDefinitions.push(definition);
}
}
- return definitionsBySequence;
+ return [sequencedDefinitions, nonSequencedDefinitions];
}
function dictTermsMergeByGloss(result, definitions, appendTo, mergedIndices) {