-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheqObjects.js
34 lines (26 loc) · 947 Bytes
/
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
const eqArrays = require('./eqArrays');
const eqObjects = function(object1, object2) {
if (Object.keys(object1).length !== Object.keys(object2).length) {
return false;
}
for (const key in object1) {
let objOneValues = object1[key];
let objTwoValues = object2[key];
// if the value is an array
if (Array.isArray(objOneValues) && Array.isArray(objTwoValues)) {
// if the value is an object
} else if (typeof(objOneValues) === "object" && typeof(objTwoValues) === "object") {
// assessing to see if the objects have the same # of properties
if (Object.keys(objOneValues).length !== Object.keys(objTwoValues).length) {
return false;
}
eqObjects(objOneValues, objTwoValues);
} else if (!eqArrays(objOneValues, objTwoValues)) {
return false;
} else if (objOneValues !== objTwoValues) {
return false;
}
}
return true;
};
module.exports = eqObjects;