aboutsummaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-02-15 13:12:03 -0500
committertoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-02-22 14:37:10 -0500
commit163211ade323f09ad9de7861e1eeab8d344bacb8 (patch)
tree972247eeea6cc91ecc675457799e320071681968 /ext
parenta4bdffbd9def55cdc8a8a5058be39d9eea42b5e9 (diff)
Use Map
Diffstat (limited to 'ext')
-rw-r--r--ext/bg/js/translator.js19
1 files changed, 10 insertions, 9 deletions
diff --git a/ext/bg/js/translator.js b/ext/bg/js/translator.js
index b850c6e4..a864712a 100644
--- a/ext/bg/js/translator.js
+++ b/ext/bg/js/translator.js
@@ -506,28 +506,29 @@ class Translator {
const names = Object.keys(items);
const tagMetaList = await this.getTagMetaList(names, title);
- const stats = {};
+ const statsGroups = new Map();
for (let i = 0; i < names.length; ++i) {
const name = names[i];
const meta = tagMetaList[i];
if (meta === null) { continue; }
const category = meta.category;
- const group = (
- hasOwn(stats, category) ?
- stats[category] :
- (stats[category] = [])
- );
+ let group = statsGroups.get(category);
+ if (typeof group === 'undefined') {
+ group = [];
+ statsGroups.set(category, group);
+ }
const stat = Object.assign({}, meta, {name, value: items[name]});
group.push(dictTagSanitize(stat));
}
+ const stats = {};
const sortCompare = (a, b) => a.notes - b.notes;
- for (const category in stats) {
- stats[category].sort(sortCompare);
+ for (const [category, group] of statsGroups.entries()) {
+ group.sort(sortCompare);
+ stats[category] = group;
}
-
return stats;
}