summaryrefslogtreecommitdiff
path: root/ext/bg/js/util.js
diff options
context:
space:
mode:
authorAlex Yatskov <alex@foosoft.net>2017-01-08 18:10:38 -0800
committerAlex Yatskov <alex@foosoft.net>2017-01-08 18:10:38 -0800
commit53a8e9061c482400186c8b041be520a519795c07 (patch)
treef503b6aad323a36579a76b65f62e3e3b14c3dece /ext/bg/js/util.js
parent148291d3a7cea096317c1c8d22f06f6e18cfdcfb (diff)
styling
Diffstat (limited to 'ext/bg/js/util.js')
-rw-r--r--ext/bg/js/util.js36
1 files changed, 2 insertions, 34 deletions
diff --git a/ext/bg/js/util.js b/ext/bg/js/util.js
index 19d08a7c..f9932a61 100644
--- a/ext/bg/js/util.js
+++ b/ext/bg/js/util.js
@@ -93,8 +93,6 @@ function undupeTermDefs(definitions) {
function groupTermDefs(definitions) {
const groups = {};
- let groupCount = 0;
-
for (const definition of definitions) {
const key = [definition.source, definition.expression].concat(definition.reasons);
if (definition.reading) {
@@ -106,50 +104,20 @@ function groupTermDefs(definitions) {
group.push(definition);
} else {
groups[key] = [definition];
- ++groupCount;
}
}
const results = [];
for (const key in groups) {
- const groupDefs = sortTermDefs(groups[key]);
-
- const tagCounts = {};
- for (const tag of groupDefs.map(def => def.tags)) {
- const count = tagCounts[tag.name] || 0;
- tagCounts[tag.name] = count + 1;
- }
-
- const tagsGlobal = [];
- const tagsGlobalAdded = {};
- let maxScore = Number.MIN_SAFE_INTEGER;
-
- for (const definition of groupDefs) {
- const tagsLocal = [];
- for (const tag of definition.tags) {
- if (tagCounts[tag.name] === groupCount) {
- if (!tagsGlobalAdded[tag.name]) {
- tagsGlobalAdded[tag.name] = true;
- tagsGlobal.push(tag);
- }
- } else {
- tagsLocal.push(tag);
- }
- }
-
- definition.tags = tagsLocal;
- maxScore = Math.max(maxScore, definition.score);
- }
-
+ const groupDefs = groups[key];
const firstDef = groupDefs[0];
results.push({
definitions: groupDefs,
expression: firstDef.expression,
reading: firstDef.reading,
reasons: firstDef.reasons,
- score: maxScore,
+ score: groupDefs.reduce((x, y) => x > y ? x : y, Number.MIN_SAFE_INTEGER),
source: firstDef.source,
- tags: sortTags(tagsGlobal),
});
}