Last active
May 28, 2021 08:42
-
-
Save konsalex/e0a7cc8e9dd5c2d1a2e3fb621e499b86 to your computer and use it in GitHub Desktop.
Deep Equality without `__proto__`
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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