-
Notifications
You must be signed in to change notification settings - Fork 0
/
eqObjectsRecursive.js
48 lines (24 loc) · 924 Bytes
/
eqObjectsRecursive.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
45
46
47
48
const eqObjectsRecursive = function (object1, object2) {
const _ = require('./index');
const eqArrays = _.eqArrays;
let result;
let index = 0;
let objectKeys1 = Object.keys(object1);
let objectKeys2 = Object.keys(object2);
if (objectKeys1.length !== objectKeys2.length) {
return false;
}
while (index < objectKeys1.length) {
if (typeof object1[objectKeys1[index]] === 'object' || typeof object2[objectKeys1[index]] === 'object') {
result = eqObjectsRecursive(object1[objectKeys1[index]], object2[objectKeys1[index]]);
} else {
result = (object1[objectKeys1[index]] instanceof Array) ? eqArrays(object1[objectKeys1[index]], object2[objectKeys1[index]]) : (object1[objectKeys1[index]] === object2[objectKeys1[index]] ? true : false);
}
if (!result) {
return false;
}
index++;
};
return result;
};
module.exports = eqObjectsRecursive;