-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharray.ts
More file actions
30 lines (30 loc) · 795 Bytes
/
Copy patharray.ts
File metadata and controls
30 lines (30 loc) · 795 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/**
* @returns whether `arr1` and `arr2` have exactly the same elements
* in exactly the same order (where "same" is defined using
* `compareElements`, defaulting to normal equality)
*/
export const equalArrays = <T>(
arr1: T[] | undefined,
arr2: T[] | undefined,
compareElements: (t1: T, t2: T) => boolean = (x, y) => x === y
): boolean => {
if (arr1 === undefined || arr2 === undefined) {
/* at least one is undefined */
if (arr1 === undefined && arr2 === undefined) {
/* both are undefined */
return true;
} else {
/* exactly one is undefined */
return false;
}
}
if (arr1.length !== arr2.length) {
return false;
}
for (let i = 0; i < arr1.length; i++) {
if (!compareElements(arr1[i], arr2[i])) {
return false;
}
}
return true;
};