Skip to content

Commit

Permalink
feat: improve perf
Browse files Browse the repository at this point in the history
  • Loading branch information
rei1024 committed Oct 22, 2024
1 parent cfe3968 commit e9f9a31
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions src/lib/getMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,27 +138,22 @@ export function getMap({
return {
periodMap: {
data: periodArray,
list: mapUnique(periodArray).filter((x) => x !== 0),
list: [...periodCountMap.keys()].sort((a, b) => a - b),
countMap: periodCountMap,
},
frequencyMap: {
data: frequencyArray,
list: mapUnique(frequencyArray).filter((x) => x !== 0),
list: [...frequencyCountMap.keys()].sort((a, b) => a - b),
countMap: frequencyCountMap,
},
heatMap: {
data: heatArray,
list: mapUnique(heatArray).filter((x) => x !== -1),
list: [...heatCountMap.keys()].sort((a, b) => a - b),
countMap: heatCountMap,
},
};
}

function mapUnique(map: number[][]): number[] {
const set = new Set(map.flat());
return [...set].sort((a, b) => a - b);
}

function getCountMap(map: number[][]): Map<number, number> {
const countMap = new Map<number, number>();
for (const row of map) {
Expand Down

0 comments on commit e9f9a31

Please sign in to comment.