Skip to content

Instantly share code, notes, and snippets.

@konsalex
Last active May 28, 2021 08:42
Show Gist options
  • Save konsalex/e0a7cc8e9dd5c2d1a2e3fb621e499b86 to your computer and use it in GitHub Desktop.
Save konsalex/e0a7cc8e9dd5c2d1a2e3fb621e499b86 to your computer and use it in GitHub Desktop.
Deep Equality without `__proto__`
/**
* Deep equality of Array of Objects
*
* Omits the __proto__ from the deep equality check also
* The assumption here is that the Array is ordered in every check.
*
* An alternative would be JSON.stringify and then check which is slow in
* large array of objects
*
*/
const arrayOfObjectsEquality = (array1: any[], array2: any[]) =>
array1?.some((item1, index) => {
const item2 = array2[index];
return !isEqual(omit(item1, ["__proto__"]), omit(item2, ["__proto__"]));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment