diff options
author | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2020-02-15 12:45:18 -0500 |
---|---|---|
committer | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2020-02-22 14:37:10 -0500 |
commit | bc94970a46171c2cd0f5feb272811487e2e1e110 (patch) | |
tree | d494a9e4528bcc8d4ee8efaa80ff4bd3fb278329 /ext/bg | |
parent | cae8ed276799f0171aa8a5d77b908b4a751c98e9 (diff) |
Use Map
Diffstat (limited to 'ext/bg')
-rw-r--r-- | ext/bg/js/dictionary.js | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/ext/bg/js/dictionary.js b/ext/bg/js/dictionary.js index 491632a0..afdd71a0 100644 --- a/ext/bg/js/dictionary.js +++ b/ext/bg/js/dictionary.js @@ -123,7 +123,7 @@ function dictTermsCompressTags(definitions) { } function dictTermsGroup(definitions, dictionaries) { - const groups = {}; + const groups = new Map(); for (const definition of definitions) { const key = [definition.source, definition.expression]; key.push(...definition.reasons); @@ -132,26 +132,27 @@ function dictTermsGroup(definitions, dictionaries) { } const keyString = key.toString(); - if (hasOwn(groups, keyString)) { - groups[keyString].push(definition); - } else { - groups[keyString] = [definition]; + let groupDefinitions = groups.get(keyString); + if (typeof groupDefinitions === 'undefined') { + groupDefinitions = []; + groups.set(keyString, groupDefinitions); } + + groupDefinitions.push(definition); } const results = []; - for (const key in groups) { - const groupDefs = groups[key]; - const firstDef = groupDefs[0]; - dictTermsSort(groupDefs, dictionaries); + for (const groupDefinitions of groups.values()) { + const firstDef = groupDefinitions[0]; + dictTermsSort(groupDefinitions, dictionaries); results.push({ - definitions: groupDefs, + definitions: groupDefinitions, expression: firstDef.expression, reading: firstDef.reading, furiganaSegments: firstDef.furiganaSegments, reasons: firstDef.reasons, termTags: firstDef.termTags, - score: groupDefs.reduce((p, v) => v.score > p ? v.score : p, Number.MIN_SAFE_INTEGER), + score: groupDefinitions.reduce((p, v) => v.score > p ? v.score : p, Number.MIN_SAFE_INTEGER), source: firstDef.source }); } |