2018-07-05 22:50:51 +02:00
|
|
|
/**
|
|
|
|
* Does a shallow compare of two arrays to determine if they are equal.
|
|
|
|
* @param a1 The first array
|
|
|
|
* @param a2 The second array
|
|
|
|
*/
|
2021-05-01 09:17:31 +02:00
|
|
|
export function compareArrays<T>(a1: T[], a2: T[]): boolean {
|
2021-09-05 01:09:30 +02:00
|
|
|
if (a1.length !== a2.length) {
|
|
|
|
return false;
|
|
|
|
}
|
2018-07-05 22:50:51 +02:00
|
|
|
|
2021-09-05 01:09:30 +02:00
|
|
|
for (let i = 0; i < a1.length; ++i) {
|
2022-05-25 21:08:48 +02:00
|
|
|
const v1 = a1[i];
|
|
|
|
const v2 = a2[i];
|
|
|
|
if (Array.isArray(v1)) {
|
2021-09-05 01:09:30 +02:00
|
|
|
// If the other element is not an array, then these cannot be equal
|
2022-05-25 21:08:48 +02:00
|
|
|
if (!Array.isArray(v2)) {
|
2021-09-05 01:09:30 +02:00
|
|
|
return false;
|
|
|
|
}
|
2019-05-02 00:20:14 +02:00
|
|
|
|
2022-05-25 21:08:48 +02:00
|
|
|
if (!compareArrays(v1, v2)) {
|
2021-09-05 01:09:30 +02:00
|
|
|
return false;
|
|
|
|
}
|
2022-05-25 21:08:48 +02:00
|
|
|
} else if (v1 !== v2 && !(Number.isNaN(v1) && Number.isNaN(v2))) {
|
2022-01-23 18:25:59 +01:00
|
|
|
// strict (in)equality considers NaN not equal to itself
|
2021-09-05 01:09:30 +02:00
|
|
|
return false;
|
2018-07-05 22:50:51 +02:00
|
|
|
}
|
2021-09-05 01:09:30 +02:00
|
|
|
}
|
2018-07-05 22:50:51 +02:00
|
|
|
|
2021-09-05 01:09:30 +02:00
|
|
|
return true;
|
2018-07-05 22:50:51 +02:00
|
|
|
}
|