mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-08 02:17:48 +00:00
Allow compareMultiple to accept compare functions in addition to order strings (#3764)
This commit is contained in:
committed by
John-David Dalton
parent
04a66a01e2
commit
79dc90dfcb
10
orderBy.js
10
orderBy.js
@@ -5,13 +5,14 @@ import baseOrderBy from './.internal/baseOrderBy.js'
|
||||
* orders of the iteratees to sort by. If `orders` is unspecified, all values
|
||||
* are sorted in ascending order. Otherwise, specify an order of "desc" for
|
||||
* descending or "asc" for ascending sort order of corresponding values.
|
||||
* You may also specify a compare function for an order.
|
||||
*
|
||||
* @since 4.0.0
|
||||
* @category Collection
|
||||
* @param {Array|Object} collection The collection to iterate over.
|
||||
* @param {Array[]|Function[]|Object[]|string[]} [iteratees=[identity]]
|
||||
* The iteratees to sort by.
|
||||
* @param {string[]} [orders] The sort orders of `iteratees`.
|
||||
* @param {(string|function)[]} [orders] The sort orders of `iteratees`.
|
||||
* @returns {Array} Returns the new sorted array.
|
||||
* @see reverse
|
||||
* @example
|
||||
@@ -26,6 +27,13 @@ import baseOrderBy from './.internal/baseOrderBy.js'
|
||||
* // Sort by `user` in ascending order and by `age` in descending order.
|
||||
* orderBy(users, ['user', 'age'], ['asc', 'desc'])
|
||||
* // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 40]]
|
||||
*
|
||||
* // Sort by `user` then by `age` using custom compare functions for each
|
||||
* orderBy(users, ['user', 'age'], [
|
||||
* (a, b) => a.localeCompare(b, 'de', { sensitivity: 'base' }),
|
||||
* (a, b) => a - b,
|
||||
* ])
|
||||
*
|
||||
*/
|
||||
function orderBy(collection, iteratees, orders) {
|
||||
if (collection == null) {
|
||||
|
||||
Reference in New Issue
Block a user