aboutsummaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-02-15 12:55:35 -0500
committertoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-02-22 14:37:10 -0500
commita4bdffbd9def55cdc8a8a5058be39d9eea42b5e9 (patch)
tree65b2a2471571aa43b627713f502341401bc0620e /ext
parent5587116baef8e243412eb9e5ad9690284944a7a3 (diff)
Use Map
Diffstat (limited to 'ext')
-rw-r--r--ext/bg/js/dictionary.js16
1 files changed, 6 insertions, 10 deletions
diff --git a/ext/bg/js/dictionary.js b/ext/bg/js/dictionary.js
index 52302e9b..febb27cc 100644
--- a/ext/bg/js/dictionary.js
+++ b/ext/bg/js/dictionary.js
@@ -79,20 +79,16 @@ function dictTermsSort(definitions, dictionaries=null) {
}
function dictTermsUndupe(definitions) {
- const definitionGroups = {};
+ const definitionGroups = new Map();
for (const definition of definitions) {
- const definitionExisting = definitionGroups[definition.id];
- if (!hasOwn(definitionGroups, definition.id) || definition.expression.length > definitionExisting.expression.length) {
- definitionGroups[definition.id] = definition;
+ const id = definition.id;
+ const definitionExisting = definitionGroups.get(id);
+ if (typeof definitionExisting === 'undefined' || definition.expression.length > definitionExisting.expression.length) {
+ definitionGroups.set(id, definition);
}
}
- const definitionsUnique = [];
- for (const key in definitionGroups) {
- definitionsUnique.push(definitionGroups[key]);
- }
-
- return definitionsUnique;
+ return [...definitionGroups.values()];
}
function dictTermsCompressTags(definitions) {