-
Notifications
You must be signed in to change notification settings - Fork 318
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #8962
- Loading branch information
Showing
5 changed files
with
107 additions
and
38 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
export function defaultEquality(a: unknown, b: unknown): boolean { | ||
return a === b | ||
} | ||
|
||
/** | ||
* Element-wise equality check of arrays. | ||
* | ||
* @param a left array | ||
* @param b right array | ||
* @param eq equality function for elements. When not specified, `===` operator is used. | ||
* @returns true if arrays are equal. | ||
*/ | ||
export function arrayEquals<T>( | ||
a: Array<T>, | ||
b: Array<T>, | ||
eq: (a: T, b: T) => boolean = defaultEquality, | ||
) { | ||
if (a.length !== b.length) return false | ||
for (let i = 0; i < a.length; ++i) { | ||
const aVal = a[i] | ||
const bVal = b[i] | ||
if ((aVal == undefined) != (bVal == undefined)) return false | ||
if (aVal != undefined && bVal != undefined && !eq(aVal, bVal)) return false | ||
} | ||
return true | ||
} |
This file contains 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