Objective: Need to find a uniqueArray of objects from two arrays of objects. The uniqueArray needs to accomodate all {key:value} changes on the objects.
While attempting to test equality, keep getting false positives.
Starting Point: Two Arrays containing database objects:
const old_workflow = [{a:1, b:2},{a:3,b:4}]
const new_workflow = [{a:1, b:2},{a:3,b:5}]
Ideal Result:
The uniqueArray must result in 1 copy of each unique objects from both arrays
const uniqueArray = [{a:1, b:2},{a:3,b:4},{a:3,b:5}]
Approaches Attempted: I tried many, but none worked, here are two examples
#1
let concatArray = new_workflow.concat(old_workflow);
let uniqueArray = [...new Set(concatArray)];
#1 Issue: I thought this was the purpose of Set(), however, the uniqueArray contains duplicates when reviewed visually
#2
const arrayUnique = (array: any) => {
let a = array.concat();
for (var i = 0; i < a.length; ++i) {
for (var j = i + 1; j < a.length; ++j) {
if (a[i] === a[j]) a.splice(j--, 1);
}
}
return a;
};
const uniqueArray = arrayUnique(new_workflow.concat(old_workflow));
#2 Issue: this uniqueArray also contains objects that have identical key:value pairs
I think the issue is that the objects are truly unique from each other, regardless of the properties… so…
How can I prove or disprove object equality? Must I go through each key?
