Projekt

Obecné

Profil

Stáhnout (860 Bajtů) Statistiky
| Větev: | Revize:
1 3a515b92 cagy
function valueOf(obj) {
2
  return obj.valueOf ? obj.valueOf() : Object.prototype.valueOf.call(obj);
3
}
4
5
function valueEqual(a, b) {
6
  // Test for strict equality first.
7
  if (a === b) return true;
8
9
  // Otherwise, if either of them == null they are not equal.
10
  if (a == null || b == null) return false;
11
12
  if (Array.isArray(a)) {
13
    return (
14
      Array.isArray(b) &&
15
      a.length === b.length &&
16
      a.every(function(item, index) {
17
        return valueEqual(item, b[index]);
18
      })
19
    );
20
  }
21
22
  if (typeof a === 'object' || typeof b === 'object') {
23
    var aValue = valueOf(a);
24
    var bValue = valueOf(b);
25
26
    if (aValue !== a || bValue !== b) return valueEqual(aValue, bValue);
27
28
    return Object.keys(Object.assign({}, a, b)).every(function(key) {
29
      return valueEqual(a[key], b[key]);
30
    });
31
  }
32
33
  return false;
34
}
35
36
export default valueEqual;