mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-05 09:27:49 +00:00
Move internal modules to “internal” folder.
This commit is contained in:
28
.internal/baseOrderBy.js
Normal file
28
.internal/baseOrderBy.js
Normal file
@@ -0,0 +1,28 @@
|
||||
import arrayMap from './.internal/arrayMap.js';
|
||||
import baseMap from './.internal/baseMap.js';
|
||||
import baseSortBy from './.internal/baseSortBy.js';
|
||||
import compareMultiple from './.internal/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) {
|
||||
let index = -1;
|
||||
iteratees = iteratees.length ? iteratees : [identity];
|
||||
|
||||
const result = baseMap(collection, (value, key, collection) => {
|
||||
const 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;
|
||||
Reference in New Issue
Block a user