Skip to content

Commit

Permalink
Set original array type passed into the function to array of ILayerTy…
Browse files Browse the repository at this point in the history
…peCount. Set return type on reduce function
  • Loading branch information
Aaron Caldwell committed Feb 18, 2020
1 parent 01ae457 commit 3bf9c38
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions x-pack/legacy/plugins/maps/server/maps_telemetry/maps_telemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,23 @@ interface Stats {
};
}

function getUniqueLayerCounts(layerCountsList: object[], mapsCount: number) {
interface ILayerTypeCount {
[key: string]: number;
}

function getUniqueLayerCounts(layerCountsList: ILayerTypeCount[], mapsCount: number) {
const uniqueLayerTypes = _.uniq(_.flatten(layerCountsList.map(lTypes => Object.keys(lTypes))));

return uniqueLayerTypes.reduce((accu: Stats, type: string) => {
const typeCounts = layerCountsList.reduce((tCountsAccu: number[], tCounts: any) => {
if (tCounts[type]) {
tCountsAccu.push(tCounts[type]);
}
return tCountsAccu;
}, []);
const typeCounts = layerCountsList.reduce(
(tCountsAccu: number[], tCounts: ILayerTypeCount): number[] => {
if (tCounts[type]) {
tCountsAccu.push(tCounts[type]);
}
return tCountsAccu;
},
[]
);
const typeCountsSum = _.sum(typeCounts);
accu[type] = {
min: typeCounts.length ? _.min(typeCounts) : 0,
Expand Down

0 comments on commit 3bf9c38

Please sign in to comment.