source: trip-planner-front/node_modules/lodash/_baseOrderBy.js@ eed0bf8

Last change on this file since eed0bf8 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 1.5 KB
RevLine 
[6a3a178]1var arrayMap = require('./_arrayMap'),
2 baseGet = require('./_baseGet'),
3 baseIteratee = require('./_baseIteratee'),
4 baseMap = require('./_baseMap'),
5 baseSortBy = require('./_baseSortBy'),
6 baseUnary = require('./_baseUnary'),
7 compareMultiple = require('./_compareMultiple'),
8 identity = require('./identity'),
9 isArray = require('./isArray');
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
49module.exports = baseOrderBy;
Note: See TracBrowser for help on using the repository browser.