helperCreateMinMax.js 688 B

1234567891011121314151617181920212223242526
  1. var isFunction = require('./isFunction')
  2. var eqNull = require('./eqNull')
  3. var get = require('./get')
  4. var arrayEach = require('./arrayEach')
  5. function helperCreateMinMax (handle) {
  6. return function (arr, iterate) {
  7. if (arr && arr.length) {
  8. var rest, itemIndex
  9. arrayEach(arr, function (itemVal, index) {
  10. if (iterate) {
  11. itemVal = isFunction(iterate) ? iterate(itemVal, index, arr) : get(itemVal, iterate)
  12. }
  13. if (!eqNull(itemVal) && (eqNull(rest) || handle(rest, itemVal))) {
  14. itemIndex = index
  15. rest = itemVal
  16. }
  17. })
  18. return arr[itemIndex]
  19. }
  20. return rest
  21. }
  22. }
  23. module.exports = helperCreateMinMax