src/js/db/table.js
/**
* fold a function on a table object
* @param {Function} Fun Function to be maped
* @param {Table} Tbl table element
* @param {Object} Acc object for accumulation
* @param {Array.<(Number|String)>} Inputs preselected colum values
* @return {Object} accumulator
*/
fold a function on a table object
fold a function on a table object
function fold(Fun, Tbl, Acc, Inputs) {
  var Data = Tbl.data, i;
  if (Inputs){
    var B,In = amap(Inputs,function(D){col(Tbl,D)});
    for (i = 0; i < Data.length; i++) {
      B = amap( function(I){return this[I];}.bind(Data[i]),In);
      B.push(Data[i]);
      B.push(i);
      Acc = Fun.apply(null,[Acc].concat(B));
    }
  } else {
    for (i = 0; i < Data.length; i++) {
      Acc = Fun(Acc,Data[i],i);
    }
  }
  return Acc;
}
function fold ( Fun , Tbl , Acc , Inputs ) { var Data = Tbl . data , i ; if ( Inputs ) { var B , In = amap ( Inputs , function ( D ) { col ( Tbl , D ) } ) ; for ( i = 0 ; i < Data . length ; i ++ ) { B = amap ( function ( I ) { return this [ I ] ; } . bind ( Data [ i ] ) , In ) ; B . push ( Data [ i ] ) ; B . push ( i ) ; Acc = Fun . apply ( null , [ Acc ] . concat ( B ) ) ; } } else { for ( i = 0 ; i < Data . length ; i ++ ) { Acc = Fun ( Acc , Data [ i ] , i ) ; } } return Acc ; }
fold a function on a table object
fold a function on a table object