1 |
3a515b92
|
cagy
|
var arrayMap = require('./_arrayMap'),
|
2 |
|
|
baseIteratee = require('./_baseIteratee'),
|
3 |
|
|
baseMap = require('./_baseMap'),
|
4 |
|
|
baseSortBy = require('./_baseSortBy'),
|
5 |
|
|
baseUnary = require('./_baseUnary'),
|
6 |
|
|
compareMultiple = require('./_compareMultiple'),
|
7 |
|
|
identity = require('./identity');
|
8 |
|
|
|
9 |
|
|
/**
|
10 |
|
|
* The base implementation of `_.orderBy` without param guards.
|
11 |
|
|
*
|
12 |
|
|
* @private
|
13 |
|
|
* @param {Array|Object} collection The collection to iterate over.
|
14 |
|
|
* @param {Function[]|Object[]|string[]} iteratees The iteratees to sort by.
|
15 |
|
|
* @param {string[]} orders The sort orders of `iteratees`.
|
16 |
|
|
* @returns {Array} Returns the new sorted array.
|
17 |
|
|
*/
|
18 |
|
|
function baseOrderBy(collection, iteratees, orders) {
|
19 |
|
|
var index = -1;
|
20 |
|
|
iteratees = arrayMap(iteratees.length ? iteratees : [identity], baseUnary(baseIteratee));
|
21 |
|
|
|
22 |
|
|
var result = baseMap(collection, function(value, key, collection) {
|
23 |
|
|
var criteria = arrayMap(iteratees, function(iteratee) {
|
24 |
|
|
return iteratee(value);
|
25 |
|
|
});
|
26 |
|
|
return { 'criteria': criteria, 'index': ++index, 'value': value };
|
27 |
|
|
});
|
28 |
|
|
|
29 |
|
|
return baseSortBy(result, function(object, other) {
|
30 |
|
|
return compareMultiple(object, other, orders);
|
31 |
|
|
});
|
32 |
|
|
}
|
33 |
|
|
|
34 |
|
|
module.exports = baseOrderBy;
|