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