forked from parse-community/parse-server
-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathequalObjects.js
More file actions
48 lines (46 loc) · 1000 Bytes
/
equalObjects.js
File metadata and controls
48 lines (46 loc) · 1000 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
37
38
39
40
41
42
43
44
45
46
47
48
var toString = Object.prototype.toString;
/**
* Determines whether two objects represent the same primitive, special Parse
* type, or full Parse Object.
*/
function equalObjects(a, b) {
if (typeof a !== typeof b) {
return false;
}
if (typeof a !== 'object') {
return (a === b);
}
if (a === b) {
return true;
}
if (toString.call(a) === '[object Date]') {
if (toString.call(b) === '[object Date]') {
return (+a === +b);
}
return false;
}
if (Array.isArray(a)) {
if (Array.isArray(b)) {
if (a.length !== b.length) {
return false;
}
for (var i = 0; i < a.length; i++) {
if (!equalObjects(a[i], b[i])) {
return false;
}
}
return true;
}
return false;
}
if (Object.keys(a).length !== Object.keys(b).length) {
return false;
}
for (var key in a) {
if (!equalObjects(a[key], b[key])) {
return false;
}
}
return true;
}
module.exports = equalObjects;