mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-05 01:17:50 +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
@@ -11,7 +11,7 @@ import compareAscending from './compareAscending.js'
|
||||
* @private
|
||||
* @param {Object} object The object to compare.
|
||||
* @param {Object} other The other object to compare.
|
||||
* @param {boolean[]|string[]} orders The order to sort by for each property.
|
||||
* @param {(string|function)[]} orders The order to sort by for each property.
|
||||
* @returns {number} Returns the sort order indicator for `object`.
|
||||
*/
|
||||
function compareMultiple(object, other, orders) {
|
||||
@@ -22,13 +22,14 @@ function compareMultiple(object, other, orders) {
|
||||
const ordersLength = orders.length
|
||||
|
||||
while (++index < length) {
|
||||
const result = compareAscending(objCriteria[index], othCriteria[index])
|
||||
var order = index < ordersLength ? orders[index] : null
|
||||
var cmpFn = (order && typeof order === 'function') ? order: compareAscending
|
||||
var result = cmpFn(objCriteria[index], othCriteria[index])
|
||||
if (result) {
|
||||
if (index >= ordersLength) {
|
||||
return result
|
||||
if (order && typeof order !== 'function') {
|
||||
return result * (order == 'desc' ? -1 : 1)
|
||||
}
|
||||
const order = orders[index]
|
||||
return result * (order == 'desc' ? -1 : 1)
|
||||
return result
|
||||
}
|
||||
}
|
||||
// Fixes an `Array#sort` bug in the JS engine embedded in Adobe applications
|
||||
|
||||
Reference in New Issue
Block a user