徐总多门店
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

26 lines
688 B

var isFunction = require('./isFunction')
var eqNull = require('./eqNull')
var get = require('./get')
var arrayEach = require('./arrayEach')
function helperCreateMinMax (handle) {
return function (arr, iterate) {
if (arr && arr.length) {
var rest, itemIndex
arrayEach(arr, function (itemVal, index) {
if (iterate) {
itemVal = isFunction(iterate) ? iterate(itemVal, index, arr) : get(itemVal, iterate)
}
if (!eqNull(itemVal) && (eqNull(rest) || handle(rest, itemVal))) {
itemIndex = index
rest = itemVal
}
})
return arr[itemIndex]
}
return rest
}
}
module.exports = helperCreateMinMax