mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-05 09:27:49 +00:00
Bump to v3.7.0.
This commit is contained in:
@@ -1,9 +1,8 @@
|
||||
import baseCallback from '../internal/baseCallback';
|
||||
import baseEach from '../internal/baseEach';
|
||||
import baseMap from '../internal/baseMap';
|
||||
import baseSortBy from '../internal/baseSortBy';
|
||||
import compareAscending from '../internal/compareAscending';
|
||||
import isIterateeCall from '../internal/isIterateeCall';
|
||||
import isLength from '../internal/isLength';
|
||||
|
||||
/**
|
||||
* Creates an array of elements, sorted in ascending order by the results of
|
||||
@@ -27,9 +26,8 @@ import isLength from '../internal/isLength';
|
||||
* @memberOf _
|
||||
* @category Collection
|
||||
* @param {Array|Object|string} collection The collection to iterate over.
|
||||
* @param {Array|Function|Object|string} [iteratee=_.identity] The function
|
||||
* invoked per iteration. If a property name or an object is provided it is
|
||||
* used to create a `_.property` or `_.matches` style callback respectively.
|
||||
* @param {Function|Object|string} [iteratee=_.identity] The function invoked
|
||||
* per iteration.
|
||||
* @param {*} [thisArg] The `this` binding of `iteratee`.
|
||||
* @returns {Array} Returns the new sorted array.
|
||||
* @example
|
||||
@@ -58,16 +56,14 @@ function sortBy(collection, iteratee, thisArg) {
|
||||
if (collection == null) {
|
||||
return [];
|
||||
}
|
||||
var index = -1,
|
||||
length = collection.length,
|
||||
result = isLength(length) ? Array(length) : [];
|
||||
|
||||
if (thisArg && isIterateeCall(collection, iteratee, thisArg)) {
|
||||
iteratee = null;
|
||||
}
|
||||
var index = -1;
|
||||
iteratee = baseCallback(iteratee, thisArg, 3);
|
||||
baseEach(collection, function(value, key, collection) {
|
||||
result[++index] = { 'criteria': iteratee(value, key, collection), 'index': index, 'value': value };
|
||||
|
||||
var result = baseMap(collection, function(value, key, collection) {
|
||||
return { 'criteria': iteratee(value, key, collection), 'index': ++index, 'value': value };
|
||||
});
|
||||
return baseSortBy(result, compareAscending);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user