I am considering using lodash's uniqWith to remove duplicates from an array of objects. However, I also want to modify each object in the array while comparing them. My idea is to add some additional logic within the comparator function to handle both tasks without setting up another loop. Is it acceptable to include extra logic like this in the comparator function?
import uniqWith from 'lodash/uniqWith';
const transformedArray = uniqWith(
arrayOfObjects,
(currObject, otherObject): boolean => {
// Implementing changes to current object properties here, is this a good approach?
if (<someCondition>) {
currObject.someProperty = true;
}
// Comparison logic between objects
if (currObject.uuid === otherObject.uuid) {
return true;
}
return false;
},
);