This commit is contained in:
毛财君
2023-07-06 17:37:33 +08:00
parent 06f26608af
commit 197b38ca6f
816 changed files with 236883 additions and 989 deletions

View File

@@ -0,0 +1,26 @@
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