1 | /**
|
2 | * lodash 4.0.0 (Custom Build) <https://lodash.com/>
|
3 | * Build: `lodash modularize exports="npm" -o ./`
|
4 | * Copyright 2012-2016 The Dojo Foundation <http://dojofoundation.org/>
|
5 | * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
|
6 | * Copyright 2009-2016 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
|
7 | * Available under MIT license <https://lodash.com/license>
|
8 | */
|
9 |
|
10 | /**
|
11 | * The base implementation of methods like `_.max` and `_.min` which accepts a
|
12 | * `comparator` to determine the extremum value.
|
13 | *
|
14 | * @private
|
15 | * @param {Array} array The array to iterate over.
|
16 | * @param {Function} iteratee The iteratee invoked per iteration.
|
17 | * @param {Function} comparator The comparator used to compare values.
|
18 | * @returns {*} Returns the extremum value.
|
19 | */
|
20 | function baseExtremum(array, iteratee, comparator) {
|
21 | var index = -1,
|
22 | length = array.length;
|
23 |
|
24 | while (++index < length) {
|
25 | var value = array[index],
|
26 | current = iteratee(value);
|
27 |
|
28 | if (current != null && (computed === undefined
|
29 | ? current === current
|
30 | : comparator(current, computed)
|
31 | )) {
|
32 | var computed = current,
|
33 | result = value;
|
34 | }
|
35 | }
|
36 | return result;
|
37 | }
|
38 |
|
39 | /**
|
40 | * Checks if `value` is greater than `other`.
|
41 | *
|
42 | * @static
|
43 | * @memberOf _
|
44 | * @category Lang
|
45 | * @param {*} value The value to compare.
|
46 | * @param {*} other The other value to compare.
|
47 | * @returns {boolean} Returns `true` if `value` is greater than `other`, else `false`.
|
48 | * @example
|
49 | *
|
50 | * _.gt(3, 1);
|
51 | * // => true
|
52 | *
|
53 | * _.gt(3, 3);
|
54 | * // => false
|
55 | *
|
56 | * _.gt(1, 3);
|
57 | * // => false
|
58 | */
|
59 | function gt(value, other) {
|
60 | return value > other;
|
61 | }
|
62 |
|
63 | /**
|
64 | * This method returns the first argument provided to it.
|
65 | *
|
66 | * @static
|
67 | * @memberOf _
|
68 | * @category Util
|
69 | * @param {*} value Any value.
|
70 | * @returns {*} Returns `value`.
|
71 | * @example
|
72 | *
|
73 | * var object = { 'user': 'fred' };
|
74 | *
|
75 | * _.identity(object) === object;
|
76 | * // => true
|
77 | */
|
78 | function identity(value) {
|
79 | return value;
|
80 | }
|
81 |
|
82 | /**
|
83 | * Computes the maximum value of `array`. If `array` is empty or falsey
|
84 | * `undefined` is returned.
|
85 | *
|
86 | * @static
|
87 | * @memberOf _
|
88 | * @category Math
|
89 | * @param {Array} array The array to iterate over.
|
90 | * @returns {*} Returns the maximum value.
|
91 | * @example
|
92 | *
|
93 | * _.max([4, 2, 8, 6]);
|
94 | * // => 8
|
95 | *
|
96 | * _.max([]);
|
97 | * // => undefined
|
98 | */
|
99 | function max(array) {
|
100 | return (array && array.length)
|
101 | ? baseExtremum(array, identity, gt)
|
102 | : undefined;
|
103 | }
|
104 |
|
105 | module.exports = max;
|