mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-01-31 15:27:50 +00:00
31 lines
1.1 KiB
JavaScript
31 lines
1.1 KiB
JavaScript
import arrayMap from './_arrayMap.js';
|
|
import baseIteratee from './_baseIteratee.js';
|
|
import baseMap from './_baseMap.js';
|
|
import baseSortBy from './_baseSortBy.js';
|
|
import baseUnary from './_baseUnary.js';
|
|
import compareMultiple from './_compareMultiple.js';
|
|
import identity from './identity.js';
|
|
|
|
/**
|
|
* 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) {
|
|
var index = -1;
|
|
iteratees = arrayMap(iteratees.length ? iteratees : [identity], baseUnary(baseIteratee));
|
|
|
|
var result = baseMap(collection, (value, key, collection) => {
|
|
var criteria = arrayMap(iteratees, iteratee => iteratee(value));
|
|
return { 'criteria': criteria, 'index': ++index, 'value': value };
|
|
});
|
|
|
|
return baseSortBy(result, (object, other) => compareMultiple(object, other, orders));
|
|
}
|
|
|
|
export default baseOrderBy;
|