Code coverage report for nodash/lib/eq.js

Statements: 100% (22 / 22)      Branches: 100% (16 / 16)      Functions: 100% (3 / 3)      Lines: 100% (22 / 22)      Ignored: none     

All files » nodash/lib/ » eq.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      1   5   1 722 344   378 378 378 4   374   197   3     46 1   45 45 109 1     44   128     5     9          
/* vim: set et sw=2 ts=2: */
'use strict';
 
module.exports = function () {
 
  var Nodash = this;
 
  function eq(a, b) {
    if (a === b) {
      return true;
    }
    var ta = Nodash.typeOf(a);
    var tb = Nodash.typeOf(b);
    if (ta !== tb) {
      return false;
    }
    switch (ta) {
      case 'tuple':
        return eq(a.fst(), b.fst()) && eq(a.snd(), b.snd());
      case 'list':
        return eq(a.head(), b.head()) && eq(a.tail(), b.tail());
      case 'array':
      case 'object':
        if (a.constructor !== b.constructor) {
          return false;
        }
        var k = Nodash.union(Object.keys(a), Object.keys(b));
        for (var i = 0; i < k.length; i++) {
          if (!eq(a[k[i]], b[k[i]])) {
            return false;
          }
        }
        return true;
    }
    return false;
  }
 
  return {
    '== eq EQ': eq,
    '/= != <> neq NEQ': function (a, b) {
      return !eq(a, b);
    }
  };
 
};