Debian Codegraph @

frontend/src/lib/equals.ts

raw
1 /** Types for which we can do a strict comparison. */
2 export type StrictEquality = string | number | null;
3
4 /**
5 * Shallow equality of two arrays - the elements are compared strictly.
6 */
7 export function shallow_equal<T extends StrictEquality>(
8 a: readonly T[],
9 b: readonly T[],
10 ): boolean {
11 const l = a.length;
12 if (l !== b.length) {
13 return false;
14 }
15
16 for (let i = 0; i < l; i += 1) {
17 if (a[i] !== b[i]) {
18 return false;
19 }
20 }
21
22 return true;
23 }