dist/bbn.js
/**
     * Sorts an array of objects based on a set of properties.
     * 
     * The resulting array is the same object, the order is based on _compareValues function
     * applied for each given properties in orders argument.
     *
     * @method   multiorder
     * @global
     * @example
     * ```javascript
     * let ar = [
     *   {movie: "Brazil", year: 1985},
     *   {movie: "Donnie Darko", year: 2001},
     *   {movie: "Out of Africa", year: 1985},
     *   {movie: "Ran", year: 1985},
     *   {movie: "Back to the future", year: 1985},
     *   {movie: "Barry Lindon", year: 1976}
     * ];
     * bbn.fn.multiorder(ar, [
     *   {field: "year", dir: "desc"},
     *   {field: "movie", dir: "asc"}
     * ]);
     * // [
     * //   {movie: "Donnie Darko", year: 2001},
     * //   {movie: "Back to the future", year: 1985},
     * //   {movie: "Brazil", year: 1985},
     * //   {movie: "Out of Africa", year: 1985},
     * //   {movie: "Ran", year: 1985},
     * //   {movie: "Barry Lindon", year: 1976}
     * // ]
     * bbn.fn.multiorder(ar, {year: "desc", movie: "asc"});
     * // Same result with object shortcut
     * ```
     * @memberof bbn.fn
     * @param    {Array}        arr    The array to order
     * @param    {Array|Object} orders The properties and directions (asc, desc) to order by
     * @returns  {Array}        The same array (arr), ordered differently
     */
Sorts an array of objects based on a set of properties.

The resulting array is the same object, the order is based on _compareValues function
applied for each given properties in orders argument.


Sorts an array of objects based on a set of properties . The resulting array is the same object the order is based on _compareValues function applied for each given properties in orders argument .
multiorder(arr, orders){
      if ( !Array.isArray(orders) && (typeof orders === 'object') ){
        let tmp = [];
        for ( var n in orders ){
          tmp.push({field: n, dir: orders[n]});
        }
        orders = tmp;
      }
      let r = arr.slice();
      return r.sort((a, b) => {
        let res;
        for ( let order of orders ){
          res = bbn.fn._compareValues(a, b, order.field, order.dir);
          if ( res !== 0 ){
            return res;
          }
        }
        return 0;
      })
    }
multiorder ( arr , orders ) { if ( ! Array . isArray ( orders ) && ( typeof orders === 'object' ) ) { let tmp = [ ] ; for ( var n in orders ) { tmp . push ( { field : n , dir : orders [ n ] } ) ; } orders = tmp ; } let r = arr . slice ( ) ; return r . sort ( ( a , b ) => { let res ; for ( let order of orders ) { res = bbn . fn . _compareValues ( a , b , order . field , order . dir ) ; if ( res !== 0 ) { return res ; } } return 0 ; } ) }
Sorts an array of objects based on a set of properties.
Sorts an array of objects based on a set of properties .