Skip to content

Commit 7f35dcd

Browse files
committed
frontend: refactor equal and inline variables
Simplifying so that TypeScript better understand the code and we can change from any to unknown in the future.
1 parent cb1e26e commit 7f35dcd

File tree

1 file changed

+10
-16
lines changed

1 file changed

+10
-16
lines changed

frontends/web/src/utils/equal.ts

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,47 +18,41 @@ const isArray = Array.isArray;
1818
const keyList = Object.keys;
1919
const hasProp = Object.prototype.hasOwnProperty;
2020

21-
export function equal(a: any, b: any): boolean {
21+
export const equal = (a: any, b: any): boolean => {
2222
if (Object.is(a, b)) {
2323
return true;
2424
}
2525

2626
if (a && b && typeof a === 'object' && typeof b === 'object') {
27-
let arrA = isArray(a), arrB = isArray(b), i: number, length: number, key: string;
28-
29-
if (arrA && arrB) {
30-
length = a.length;
31-
if (length !== b.length) {
27+
if (isArray(a) && isArray(b)) {
28+
if (a.length !== b.length) {
3229
return false;
3330
}
34-
for (i = 0; i < length; i++) {
31+
for (let i = 0; i < a.length; i++) {
3532
if (!equal(a[i], b[i])) {
3633
return false;
3734
}
3835
}
3936
return true;
4037
}
4138

42-
if (arrA !== arrB) {
39+
if (isArray(a) !== isArray(b)) {
4340
return false;
4441
}
4542

46-
let keys = keyList(a);
47-
length = keys.length;
48-
43+
const length = keyList(a).length;
4944
if (length !== keyList(b).length) {
5045
return false;
5146
}
5247

53-
for (i = 0; i < length; i++) {
54-
if (!hasProp.call(b, keys[i])) {
48+
for (let i = 0; i < length; i++) {
49+
if (!hasProp.call(b, keyList(a)[i])) {
5550
return false;
5651
}
5752
}
5853

59-
for (i = 0; i < length; i++) {
60-
key = keys[i];
61-
if (!equal(a[key], b[key])) {
54+
for (let i = 0; i < length; i++) {
55+
if (!equal(a[keyList(a)[i]], b[keyList(a)[i]])) {
6256
return false;
6357
}
6458
}

0 commit comments

Comments
 (0)