summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-03-28 13:20:42 -0400
committertoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-03-28 14:50:10 -0400
commita339bf69d3841fa97ce9f6673472bd451b813937 (patch)
treedd9bb884d09b90e8adc0e58d40da0a2dcc0be6e3 /ext
parent2c4983da46c076298532f6357c594d81d4676eee (diff)
Move set functions into core.js
Diffstat (limited to 'ext')
-rw-r--r--ext/bg/js/dictionary.js32
-rw-r--r--ext/mixed/js/core.js24
2 files changed, 28 insertions, 28 deletions
diff --git a/ext/bg/js/dictionary.js b/ext/bg/js/dictionary.js
index 3dd1d0c1..74bd5a64 100644
--- a/ext/bg/js/dictionary.js
+++ b/ext/bg/js/dictionary.js
@@ -137,30 +137,6 @@ function dictTermsGroup(definitions, dictionaries) {
return dictTermsSort(results);
}
-function dictAreSetsEqual(set1, set2) {
- if (set1.size !== set2.size) {
- return false;
- }
-
- for (const value of set1) {
- if (!set2.has(value)) {
- return false;
- }
- }
-
- return true;
-}
-
-function dictGetSetIntersection(set1, set2) {
- const result = [];
- for (const value of set1) {
- if (set2.has(value)) {
- result.push(value);
- }
- }
- return result;
-}
-
function dictTermsMergeBySequence(definitions, mainDictionary) {
const sequencedDefinitions = new Map();
const nonSequencedDefinitions = [];
@@ -281,11 +257,11 @@ function dictTermsMergeByGloss(result, definitions, appendTo=null, mergedIndices
const only = [];
const expressionSet = definition.expression;
const readingSet = definition.reading;
- if (!dictAreSetsEqual(expressionSet, resultExpressionSet)) {
- only.push(...dictGetSetIntersection(expressionSet, resultExpressionSet));
+ if (!areSetsEqual(expressionSet, resultExpressionSet)) {
+ only.push(...getSetIntersection(expressionSet, resultExpressionSet));
}
- if (!dictAreSetsEqual(readingSet, resultReadingSet)) {
- only.push(...dictGetSetIntersection(readingSet, resultReadingSet));
+ if (!areSetsEqual(readingSet, resultReadingSet)) {
+ only.push(...getSetIntersection(readingSet, resultReadingSet));
}
definition.only = only;
}
diff --git a/ext/mixed/js/core.js b/ext/mixed/js/core.js
index 0d50e915..fd762e97 100644
--- a/ext/mixed/js/core.js
+++ b/ext/mixed/js/core.js
@@ -132,6 +132,30 @@ function parseUrl(url) {
return {baseUrl, queryParams};
}
+function areSetsEqual(set1, set2) {
+ if (set1.size !== set2.size) {
+ return false;
+ }
+
+ for (const value of set1) {
+ if (!set2.has(value)) {
+ return false;
+ }
+ }
+
+ return true;
+}
+
+function getSetIntersection(set1, set2) {
+ const result = [];
+ for (const value of set1) {
+ if (set2.has(value)) {
+ result.push(value);
+ }
+ }
+ return result;
+}
+
/*
* Async utilities