Example #1
0
File: nddb.js Project: uramer/NDDB
 NDDB.prototype.groupBy = function (key) {
     if (!key) return this.db;
     
     var groups = [];
     var outs = [];
     for (var i=0; i < this.db.length; i++) {
         var el = JSUS.getNestedValue(key, this.db[i]);
         if ('undefined' === typeof el) continue;
         
         // Creates a new group and add entries
         // into it
         if (!JSUS.in_array(el, groups)) {
             groups.push(el);
             
             var out = this.filter(function (elem) {
                 if (JSUS.equals(JSUS.getNestedValue(key, elem),el)) {
                     return this;
                 }
             });
             
             outs.push(out);
         }
         
     }
     
     //NDDB.log(groups);
     
     return outs;
 };    
Example #2
0
File: nddb.js Project: uramer/NDDB
        return ('undefined' !== typeof this.D[d]) ? this.D[d] : function (o1, o2) {
//            NDDB.log('1' + o1);
//            NDDB.log('2' + o2);
            if (!o1 && !o2) return 0;
            if (!o1) return -1;
            if (!o2) return 1;        
            var v1 = JSUS.getNestedValue(d,o1);
            var v2 = JSUS.getNestedValue(d,o2);
//            NDDB.log(v1);
//            NDDB.log(v2);
            if (!v1 && !v2) return 0;
            if (!v1) return -1;
            if (!v2) return 1;
            if (v1 > v2) return 1;
            if (v2 > v1) return -1;
            return 0;
        };    
Example #3
0
File: nddb.js Project: uramer/NDDB
 NDDB.prototype.sum = function (key) {
     var sum = 0;
     for (var i=0; i < this.db.length; i++) {
         try {
             var tmp = JSUS.getNestedValue(key, this.db[i]);
             if (!isNaN(tmp)) {
                 sum += tmp;
             }
         }
         catch (e) {};
     }    
     return sum;
 };
Example #4
0
File: nddb.js Project: uramer/NDDB
 function getKeyValuesArray (o, key) {
     var el = JSUS.getNestedValue(key, o);
     if ('undefined' !== typeof el) {
         return key.split('.').concat(JSUS.obj2KeyedArray(el));
     }
 };
Example #5
0
File: nddb.js Project: uramer/NDDB
 function getValuesArray (o, key) {
     var el = JSUS.getNestedValue(key, o);
     if ('undefined' !== typeof el) {
         return JSUS.obj2KeyedArray(el);
     }
 };
Example #6
0
File: nddb.js Project: uramer/NDDB
 function getValues (o, key) {        
     return JSUS.getNestedValue(key, o);
 };
Example #7
0
File: nddb.js Project: uramer/NDDB
 var notinarray = function (elem) {
     if (!JSUS.in_array(JSUS.getNestedValue(d,elem), value)) {
         return elem;
     }
 };
Example #8
0
File: nddb.js Project: uramer/NDDB
 var exist = function (elem) {
     if ('undefined' !== typeof JSUS.getNestedValue(d,elem)) return elem;
 };
Example #9
0
File: nddb.js Project: uramer/NDDB
 var out = this.filter(function (elem) {
     if (JSUS.equals(JSUS.getNestedValue(key, elem),el)) {
         return this;
     }
 });