-
Notifications
You must be signed in to change notification settings - Fork 0
/
eqObjects.js
44 lines (32 loc) · 1.21 KB
/
eqObjects.js
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
let equivalent = false;
if (Object.keys(object1).length === Object.keys(object2).length) {
for (let property in object1) {
for (let property2 in object2) {
if (property === property2) { //both keys are the same
if (typeof object1[property] === "object" || typeof object2[property] === "object") { //when either obj1 or obj2 value is equal to non-primitive type (array or obj)
if (object1[property].length === object2[property].length) { //if array/ objects are equal length
for (let value of object1[property]) {
for (let value2 of object2[property]) {
if (value === value2) { //if array element is the same
equivalent = true;
} else {
equivalent = false;
}
}
}
} else {
equivalent = false;
}
} else { //when equal to primitive type
if (object1[property] === object2[property]) { //both values are the same
equivalent = true;
} else {
equivalent = false;
}
}
}
}
}
}
console.log(equivalent);
return equivalent;