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
clapton-0.0.1 lib/clapton/javascripts/node_modules/lodash/_baseOrderBy.js
immosquare-cleaner-0.1.47 node_modules/lodash/_baseOrderBy.js
immosquare-cleaner-0.1.46 node_modules/lodash/_baseOrderBy.js
immosquare-cleaner-0.1.45 node_modules/lodash/_baseOrderBy.js
immosquare-cleaner-0.1.44 node_modules/lodash/_baseOrderBy.js
boring_generators-0.14.0 tmp/templates/app_template/node_modules/lodash/_baseOrderBy.js
immosquare-cleaner-0.1.43 node_modules/lodash/_baseOrderBy.js
immosquare-cleaner-0.1.42 node_modules/lodash/_baseOrderBy.js
immosquare-cleaner-0.1.41 node_modules/lodash/_baseOrderBy.js
immosquare-cleaner-0.1.40 node_modules/lodash/_baseOrderBy.js
immosquare-cleaner-0.1.39 node_modules/lodash/_baseOrderBy.js
immosquare-cleaner-0.1.38 node_modules/lodash/_baseOrderBy.js
optimacms-0.1.61 spec/dummy/node_modules/lodash/_baseOrderBy.js
boring_generators-0.13.0 tmp/templates/app_template/node_modules/lodash/_baseOrderBy.js
immosquare-cleaner-0.1.32 node_modules/lodash/_baseOrderBy.js
immosquare-cleaner-0.1.31 node_modules/lodash/_baseOrderBy.js
immosquare-cleaner-0.1.30 node_modules/lodash/_baseOrderBy.js
immosquare-cleaner-0.1.29 node_modules/lodash/_baseOrderBy.js
immosquare-cleaner-0.1.28 node_modules/lodash/_baseOrderBy.js
immosquare-cleaner-0.1.27 node_modules/lodash/_baseOrderBy.js