mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-06 17:47:49 +00:00
Bump to v4.14.0.
This commit is contained in:
16
sortBy.js
16
sortBy.js
@@ -1,9 +1,7 @@
|
||||
import baseFlatten from './_baseFlatten.js';
|
||||
import baseOrderBy from './_baseOrderBy.js';
|
||||
import isArray from './isArray.js';
|
||||
import isFlattenableIteratee from './_isFlattenableIteratee.js';
|
||||
import baseRest from './_baseRest.js';
|
||||
import isIterateeCall from './_isIterateeCall.js';
|
||||
import rest from './rest.js';
|
||||
|
||||
/**
|
||||
* Creates an array of elements, sorted in ascending order by the results of
|
||||
@@ -16,8 +14,8 @@ import rest from './rest.js';
|
||||
* @since 0.1.0
|
||||
* @category Collection
|
||||
* @param {Array|Object} collection The collection to iterate over.
|
||||
* @param {...(Array|Array[]|Function|Function[]|Object|Object[]|string|string[])}
|
||||
* [iteratees=[_.identity]] The iteratees to sort by.
|
||||
* @param {...(Function|Function[])} [iteratees=[_.identity]]
|
||||
* The iteratees to sort by.
|
||||
* @returns {Array} Returns the new sorted array.
|
||||
* @example
|
||||
*
|
||||
@@ -39,7 +37,7 @@ import rest from './rest.js';
|
||||
* });
|
||||
* // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 40]]
|
||||
*/
|
||||
var sortBy = rest(function(collection, iteratees) {
|
||||
var sortBy = baseRest(function(collection, iteratees) {
|
||||
if (collection == null) {
|
||||
return [];
|
||||
}
|
||||
@@ -49,11 +47,7 @@ var sortBy = rest(function(collection, iteratees) {
|
||||
} else if (length > 2 && isIterateeCall(iteratees[0], iteratees[1], iteratees[2])) {
|
||||
iteratees = [iteratees[0]];
|
||||
}
|
||||
iteratees = (iteratees.length == 1 && isArray(iteratees[0]))
|
||||
? iteratees[0]
|
||||
: baseFlatten(iteratees, 1, isFlattenableIteratee);
|
||||
|
||||
return baseOrderBy(collection, iteratees, []);
|
||||
return baseOrderBy(collection, baseFlatten(iteratees, 1), []);
|
||||
});
|
||||
|
||||
export default sortBy;
|
||||
|
||||
Reference in New Issue
Block a user