I have two objects:
Object One
[
{ repo: 'edat-ims-github', status: 200 },
{ repo: 'edat-ims-github-spa', status: 200 },
{ repo: 'test-repo-three', status: 200 }
]
Object Two
[
{ repo: 'edat-ims-github', status: 200 },
{ repo: 'edat-ims-github-spa', status: 200 },
{ repo: 'test-repo-one', status: 200 },
{ repo: 'test-repo-two', status: 200 },
{ repo: 'test-repo-three', status: 200 }
]
I would like to compare both arrays and remove the duplicate objects from the second array so my output looks like:
[
{ repo: 'test-repo-one', status: 200 },
{ repo: 'test-repo-two', status: 200 }
]
I have tried to use ES6 to do this by running this:
const result = objectTwo.filter((obj) => {
return !objectOne.includes(obj);
});
However, result is coming out as:
[
{ repo: 'edat-ims-github', status: 200 },
{ repo: 'edat-ims-github-spa', status: 200 },
{ repo: 'test-repo-one', status: 200 },
{ repo: 'test-repo-two', status: 200 },
{ repo: 'test-repo-three', status: 200 }
]
Could someone please guide me on where I am going wrong and what the most optimal way of achieving this would be? In real life, both arrays have are 10000+ objects.
I am not testing equality as both arrays are not the same, I am more testing how to remove duplicates.
Thanks :)