1 var baseFlatten = require('../internal/baseFlatten'),
2 baseSortByOrder = require('../internal/baseSortByOrder'),
3 isIterateeCall = require('../internal/isIterateeCall'),
4 restParam = require('../function/restParam');
7 * This method is like `_.sortBy` except that it can sort by multiple iteratees
10 * If a property name is provided for an iteratee the created `_.property`
11 * style callback returns the property value of the given element.
13 * If an object is provided for an iteratee the created `_.matches` style
14 * callback returns `true` for elements that have the properties of the given
15 * object, else `false`.
19 * @category Collection
20 * @param {Array|Object|string} collection The collection to iterate over.
21 * @param {...(Function|Function[]|Object|Object[]|string|string[])} iteratees
22 * The iteratees to sort by, specified as individual values or arrays of values.
23 * @returns {Array} Returns the new sorted array.
27 * { 'user': 'fred', 'age': 48 },
28 * { 'user': 'barney', 'age': 36 },
29 * { 'user': 'fred', 'age': 42 },
30 * { 'user': 'barney', 'age': 34 }
33 * _.map(_.sortByAll(users, ['user', 'age']), _.values);
34 * // => [['barney', 34], ['barney', 36], ['fred', 42], ['fred', 48]]
36 * _.map(_.sortByAll(users, 'user', function(chr) {
37 * return Math.floor(chr.age / 10);
39 * // => [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 42]]
41 var sortByAll = restParam(function(collection, iteratees) {
42 if (collection == null) {
45 var guard = iteratees[2];
46 if (guard && isIterateeCall(iteratees[0], iteratees[1], guard)) {
49 return baseSortByOrder(collection, baseFlatten(iteratees), []);
52 module.exports = sortByAll;