Use Map
This commit is contained in:
parent
5587116bae
commit
a4bdffbd9d
@ -79,20 +79,16 @@ function dictTermsSort(definitions, dictionaries=null) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function dictTermsUndupe(definitions) {
|
function dictTermsUndupe(definitions) {
|
||||||
const definitionGroups = {};
|
const definitionGroups = new Map();
|
||||||
for (const definition of definitions) {
|
for (const definition of definitions) {
|
||||||
const definitionExisting = definitionGroups[definition.id];
|
const id = definition.id;
|
||||||
if (!hasOwn(definitionGroups, definition.id) || definition.expression.length > definitionExisting.expression.length) {
|
const definitionExisting = definitionGroups.get(id);
|
||||||
definitionGroups[definition.id] = definition;
|
if (typeof definitionExisting === 'undefined' || definition.expression.length > definitionExisting.expression.length) {
|
||||||
|
definitionGroups.set(id, definition);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const definitionsUnique = [];
|
return [...definitionGroups.values()];
|
||||||
for (const key in definitionGroups) {
|
|
||||||
definitionsUnique.push(definitionGroups[key]);
|
|
||||||
}
|
|
||||||
|
|
||||||
return definitionsUnique;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function dictTermsCompressTags(definitions) {
|
function dictTermsCompressTags(definitions) {
|
||||||
|
Loading…
Reference in New Issue
Block a user