Skip to content

Commit

Permalink
removed unnecessary loops
Browse files Browse the repository at this point in the history
Signed-off-by: sumukhswamy <[email protected]>
  • Loading branch information
sumukhswamy committed Jan 27, 2025
1 parent 92af2c8 commit 0b43116
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions server/routes/utils/dataReportHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,22 +302,18 @@ function traverse(data: any, keys: string[], result: { [key: string]: any } = {}

keys.forEach((key) => {
const value = _.get(data, key, undefined);

if (value !== undefined) {
result[key] = value;
} else {
Object.keys(data)
.filter((sourceKey) => sourceKey.startsWith(key + '.'))
.forEach((sourceKey) => {
result[sourceKey] = data[sourceKey];
});

const flattenedValues: { [key: string]: any[] } = {};

Object.keys(data).forEach((dataKey) => {
if (dataKey.startsWith(key + '.')) {
result[dataKey] = data[dataKey];
}
const arrayValue = data[dataKey];

if (Array.isArray(arrayValue)) {
const flattenedValues: { [key: string]: any[] } = {};

arrayValue.forEach((item) => {
if (typeof item === 'object' && item !== null) {
Object.keys(item).forEach((subKey) => {
Expand All @@ -329,14 +325,15 @@ function traverse(data: any, keys: string[], result: { [key: string]: any } = {}
});
}
});

Object.keys(flattenedValues).forEach((newKey) => {
result[newKey] = flattenedValues[newKey];
});
}
});

Object.keys(flattenedValues).forEach((newKey) => {
result[newKey] = flattenedValues[newKey];
});
}
});

return result;
}

Expand Down

0 comments on commit 0b43116

Please sign in to comment.