diff options
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/wiki-data.js | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/src/util/wiki-data.js b/src/util/wiki-data.js index 3e564b96..97ffab76 100644 --- a/src/util/wiki-data.js +++ b/src/util/wiki-data.js @@ -152,14 +152,25 @@ export function sortByDirectory( } export function sortByName(data, {getName = (o) => o.name} = {}) { + const nameMap = new Map(); + const normalizedNameMap = new Map(); + for (const o of data) { + const name = getName(o); + const normalizedName = normalizeName(name); + nameMap.set(o, name); + normalizedNameMap.set(o, normalizedName); + } + return data.sort((a, b) => { - const an = getName(a); - const bn = getName(b); - const ann = normalizeName(an); - const bnn = normalizeName(bn); - return ( - compareCaseLessSensitive(ann, bnn) || compareCaseLessSensitive(an, bn) - ); + const ann = normalizedNameMap.get(a); + const bnn = normalizedNameMap.get(b); + const comparison = compareCaseLessSensitive(ann, bnn); + if (comparison !== 0) + return comparison; + + const an = nameMap.get(a); + const bn = nameMap.get(b); + return compareCaseLessSensitive(an, bn); }); } |