Projekt

Obecné

Profil

Stáhnout (877 Bajtů) Statistiky
| Větev: | Revize:
1
'use strict';
2

    
3
function valueOf(obj) {
4
  return obj.valueOf ? obj.valueOf() : Object.prototype.valueOf.call(obj);
5
}
6

    
7
function valueEqual(a, b) {
8
  // Test for strict equality first.
9
  if (a === b) return true;
10

    
11
  // Otherwise, if either of them == null they are not equal.
12
  if (a == null || b == null) return false;
13

    
14
  if (Array.isArray(a)) {
15
    return (
16
      Array.isArray(b) &&
17
      a.length === b.length &&
18
      a.every(function(item, index) {
19
        return valueEqual(item, b[index]);
20
      })
21
    );
22
  }
23

    
24
  if (typeof a === 'object' || typeof b === 'object') {
25
    var aValue = valueOf(a);
26
    var bValue = valueOf(b);
27

    
28
    if (aValue !== a || bValue !== b) return valueEqual(aValue, bValue);
29

    
30
    return Object.keys(Object.assign({}, a, b)).every(function(key) {
31
      return valueEqual(a[key], b[key]);
32
    });
33
  }
34

    
35
  return false;
36
}
37

    
38
module.exports = valueEqual;
(1-1/2)