Sha256: 36b05eeea5d10c43aa3c0c68ea2e18f0a38c643e7ff07c8464086e1d65ba3e32

Contents?: true

Size: 1.52 KB

Versions: 118

Compression:

Stored size: 1.52 KB

Contents

var arrayMap = require('./_arrayMap'),
    baseGet = require('./_baseGet'),
    baseIteratee = require('./_baseIteratee'),
    baseMap = require('./_baseMap'),
    baseSortBy = require('./_baseSortBy'),
    baseUnary = require('./_baseUnary'),
    compareMultiple = require('./_compareMultiple'),
    identity = require('./identity'),
    isArray = require('./isArray');

/**
 * The base implementation of `_.orderBy` without param guards.
 *
 * @private
 * @param {Array|Object} collection The collection to iterate over.
 * @param {Function[]|Object[]|string[]} iteratees The iteratees to sort by.
 * @param {string[]} orders The sort orders of `iteratees`.
 * @returns {Array} Returns the new sorted array.
 */
function baseOrderBy(collection, iteratees, orders) {
  if (iteratees.length) {
    iteratees = arrayMap(iteratees, function(iteratee) {
      if (isArray(iteratee)) {
        return function(value) {
          return baseGet(value, iteratee.length === 1 ? iteratee[0] : iteratee);
        }
      }
      return iteratee;
    });
  } else {
    iteratees = [identity];
  }

  var index = -1;
  iteratees = arrayMap(iteratees, baseUnary(baseIteratee));

  var result = baseMap(collection, function(value, key, collection) {
    var criteria = arrayMap(iteratees, function(iteratee) {
      return iteratee(value);
    });
    return { 'criteria': criteria, 'index': ++index, 'value': value };
  });

  return baseSortBy(result, function(object, other) {
    return compareMultiple(object, other, orders);
  });
}

module.exports = baseOrderBy;

Version data entries

118 entries across 117 versions & 11 rubygems

Version Path
immosquare-cleaner-0.1.60 node_modules/lodash/_baseOrderBy.js
immosquare-cleaner-0.1.59 node_modules/lodash/_baseOrderBy.js
immosquare-cleaner-0.1.58 node_modules/lodash/_baseOrderBy.js
immosquare-cleaner-0.1.57 node_modules/lodash/_baseOrderBy.js
immosquare-cleaner-0.1.56 node_modules/lodash/_baseOrderBy.js
immosquare-cleaner-0.1.55 node_modules/lodash/_baseOrderBy.js
immosquare-cleaner-0.1.54 node_modules/lodash/_baseOrderBy.js
immosquare-cleaner-0.1.53 node_modules/lodash/_baseOrderBy.js
immosquare-cleaner-0.1.52 node_modules/lodash/_baseOrderBy.js
trusty-cms-6.3.1 node_modules/lodash/_baseOrderBy.js
immosquare-cleaner-0.1.51 node_modules/lodash/_baseOrderBy.js
boring_generators-0.15.0 tmp/templates/app_template/node_modules/lodash/_baseOrderBy.js
clapton-0.0.26 lib/clapton/javascripts/node_modules/lodash/_baseOrderBy.js
clapton-0.0.25 lib/clapton/javascripts/node_modules/lodash/_baseOrderBy.js
immosquare-cleaner-0.1.50 node_modules/lodash/_baseOrderBy.js
clapton-0.0.24 lib/clapton/javascripts/node_modules/lodash/_baseOrderBy.js
clapton-0.0.23 lib/clapton/javascripts/node_modules/lodash/_baseOrderBy.js
clapton-0.0.22 lib/clapton/javascripts/node_modules/lodash/_baseOrderBy.js
clapton-0.0.21 lib/clapton/javascripts/node_modules/lodash/_baseOrderBy.js
clapton-0.0.20 lib/clapton/javascripts/node_modules/lodash/_baseOrderBy.js