-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathassertObjectsEqual.js
More file actions
36 lines (30 loc) · 955 Bytes
/
Copy pathassertObjectsEqual.js
File metadata and controls
36 lines (30 loc) · 955 Bytes
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
const eqObjects = function(object1, object2) {
const keys1 = Object.keys(object1)
const keys2 = Object.keys(object2)
if(keys1.length = keys2.length){
for(key of keys1){
if(Array.isArray(object1[key]) || Array.isArray(object2[key])) {
if(object1[key].length === object2[key].length){
eq(object1[key], object2[key]);
} else {
return false;
}
} else{
if(object1[key] === object2[key]){
} else return false;
}
}
} else return false;
return true;
}
const assertObjectsEqual = function(object1, object2) {
const inspect = require('util').inspect;
if (eqObjects(object1, object2)) {
console.log(`The '${object1}' and the '${object2}' are the same✅`);
return true;
}
console.log(`The '${object1}' and the '${object2}' are not same ❌`);
}
const ab = { a: "1", b: "2" };
const ba = { b: "2", a: "1" };
assertObjectsEqual(ab, ba);