From 7d706df66b4cd68d6ac430c2e3e8b9f3a7f4b6ae Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Thu, 7 Jan 2021 20:24:22 -0500 Subject: Update DictionaryDataUtil to be able to be used in a sandbox frame (#1206) --- ext/mixed/js/dictionary-data-util.js | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) (limited to 'ext/mixed') diff --git a/ext/mixed/js/dictionary-data-util.js b/ext/mixed/js/dictionary-data-util.js index c049d591..8d8772fe 100644 --- a/ext/mixed/js/dictionary-data-util.js +++ b/ext/mixed/js/dictionary-data-util.js @@ -52,8 +52,8 @@ class DictionaryDataUtil { const exclusiveExpressions = []; const exclusiveReadings = []; const resultExpressions = result.expressions; - if (!areSetsEqual(resultExpressions, allExpressions)) { - exclusiveExpressions.push(...getSetIntersection(resultExpressions, allExpressions)); + if (!this._areSetsEqual(resultExpressions, allExpressions)) { + exclusiveExpressions.push(...this._getSetIntersection(resultExpressions, allExpressions)); } if (multipleReadings) { exclusiveReadings.push(result.reading); @@ -71,6 +71,8 @@ class DictionaryDataUtil { return results2; } + // Private + static _findExistingPitchAccentInfo(reading, position, tags, pitchAccentInfoList) { for (const pitchInfo of pitchAccentInfoList) { if ( @@ -98,4 +100,28 @@ class DictionaryDataUtil { return true; } + + static _areSetsEqual(set1, set2) { + if (set1.size !== set2.size) { + return false; + } + + for (const value of set1) { + if (!set2.has(value)) { + return false; + } + } + + return true; + } + + static _getSetIntersection(set1, set2) { + const result = []; + for (const value of set1) { + if (set2.has(value)) { + result.push(value); + } + } + return result; + } } -- cgit v1.2.3