Spaces:
Paused
Paused
File size: 910 Bytes
0e759d2 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
export function deduplicateObjectsArray(objArray: { [key: string]: any[] }): {
[key: string]: any[];
} {
const deduplicatedObjArray: { [key: string]: any[] } = {};
for (const key in objArray) {
if (Array.isArray(objArray[key])) {
const seen = new Set();
deduplicatedObjArray[key] = objArray[key].filter((item) => {
// Create a unique identifier for each item based on its properties
const identifier = JSON.stringify(item);
// Check if this identifier has been seen before
if (seen.has(identifier)) {
return false; // Duplicate found, filter it out
}
// Add the identifier to the set and keep the item
seen.add(identifier);
return true;
});
} else {
// If the value is not an array, just copy it as is
deduplicatedObjArray[key] = objArray[key];
}
}
return deduplicatedObjArray;
}
|