Skip to content

Commit

Permalink
optimize town de-duping
Browse files Browse the repository at this point in the history
  • Loading branch information
Owen3H committed Sep 12, 2023
1 parent 36cdfbd commit f72a459
Showing 1 changed file with 21 additions and 12 deletions.
33 changes: 21 additions & 12 deletions src/classes/Towns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,7 @@ class Towns implements Base {
throw new ReferenceError('No areas found on markerset!')
}

cachedTowns = []

const townsArray = [],
const townsArray: Town[] = [],
townData = Object.keys(markerset.areas).map(key => markerset.areas[key]),
len = townData.length

Expand Down Expand Up @@ -119,18 +117,29 @@ class Towns implements Base {
townsArray.push(currentTown)
}

//#region Remove duplicates & add to area
const temp: Record<string, Town> = {}

//#region Remove duplicates & add to area
townsArray.forEach(a => {
const name = a.name
// townsArray.forEach(a => {
// const name = a.name

if (temp[name]) temp[name].area += a.area
else {
temp[name] = a
cachedTowns.push(temp[name])
}
}, {})
// if (temp[name]) temp[name].area += a.area
// else {
// temp[name] = a
// cachedTowns.push(temp[name])
// }
// }, {})

const townsArrLen = townsArray.length
for (let i = 0; i < townsArrLen; i++) {
const town = townsArray[i]
const name = town.name

if (temp[name]) temp[name].area += town.area
else temp[name] = town
}

cachedTowns = Object.values(temp)
//#endregion

if (cachedTowns.length > 0) {
Expand Down

0 comments on commit f72a459

Please sign in to comment.