source: imaps-frontend/node_modules/lodash-es/_baseOrderBy.js@ d565449

main
Last change on this file since d565449 was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 1.5 KB
Line 
1import arrayMap from './_arrayMap.js';
2import baseGet from './_baseGet.js';
3import baseIteratee from './_baseIteratee.js';
4import baseMap from './_baseMap.js';
5import baseSortBy from './_baseSortBy.js';
6import baseUnary from './_baseUnary.js';
7import compareMultiple from './_compareMultiple.js';
8import identity from './identity.js';
9import isArray from './isArray.js';
10
11/**
12 * The base implementation of `_.orderBy` without param guards.
13 *
14 * @private
15 * @param {Array|Object} collection The collection to iterate over.
16 * @param {Function[]|Object[]|string[]} iteratees The iteratees to sort by.
17 * @param {string[]} orders The sort orders of `iteratees`.
18 * @returns {Array} Returns the new sorted array.
19 */
20function baseOrderBy(collection, iteratees, orders) {
21 if (iteratees.length) {
22 iteratees = arrayMap(iteratees, function(iteratee) {
23 if (isArray(iteratee)) {
24 return function(value) {
25 return baseGet(value, iteratee.length === 1 ? iteratee[0] : iteratee);
26 }
27 }
28 return iteratee;
29 });
30 } else {
31 iteratees = [identity];
32 }
33
34 var index = -1;
35 iteratees = arrayMap(iteratees, baseUnary(baseIteratee));
36
37 var result = baseMap(collection, function(value, key, collection) {
38 var criteria = arrayMap(iteratees, function(iteratee) {
39 return iteratee(value);
40 });
41 return { 'criteria': criteria, 'index': ++index, 'value': value };
42 });
43
44 return baseSortBy(result, function(object, other) {
45 return compareMultiple(object, other, orders);
46 });
47}
48
49export default baseOrderBy;
Note: See TracBrowser for help on using the repository browser.