Code coverage report for nodash/lib/ord.js

Statements: 100% (24 / 24)      Branches: 100% (13 / 13)      Functions: 100% (9 / 9)      Lines: 100% (24 / 24)      Ignored: none     

All files » nodash/lib/ » ord.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 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64      1   5   1 222   16   12 3 9 7 11 11 5     2   2   193   1     5         14       13       3       16       18       90       3        
/* vim: set et sw=2 ts=2: */
'use strict';
 
module.exports = function () {
 
  var Nodash = this;
  
  function compare(a, b) {
    switch (typeof a) {
    case 'string':
      return a.localeCompare(b);
    case 'object':
      if (Nodash.isFunction(a.compareTo)) {
        return a.compareTo(b);
      } else if (Nodash.isArray(a)) {
        for (var i = 0; i < Math.min(a.length, b.length); i++) {
          var r = Nodash.compare(a[i], b[i]);
          if (r !== 0) {
              return r;
          }
        }
        return 0;
      }
      return a.toString().localeCompare(b.toString());
    case 'number':
      return Nodash.signum(a - b);
    }
    return undefined;
  }
 
  return {
    
    compare: compare,
 
    '< lt LT': function (a, b) {
      return compare(a, b) < 0;
    },
    
    '> gt GT': function (a, b) {
      return compare(a, b) > 0;
    },
 
    '<= lte LTE': function (a, b) {
      return compare(a, b) <= 0;
    },
 
    '>= gte GTE': function (a, b) {
      return compare(a, b) >= 0;
    },
 
    max: function (a, b) {
      return compare(a, b) > 0 ? a : b;
    },
 
    min: function (a, b) {
      return compare(a, b) < 0 ? a : b;
    },
 
    comparing: function (f, a, b) {
      return compare(f(a), f(b));
    }
  };
};