UNPKG

xe-utils

Version:

JavaScript 函数库、工具类

21 lines (19 loc) • 704 B
import isFunction from './isFunction.js';import eqNull from './eqNull.js';import get from './get.js';import arrayEach from './arrayEach.js';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 } } export default helperCreateMinMax