Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
80742 views
1
var baseEach = require('./baseEach');
2
3
/**
4
* Gets the extremum value of `collection` invoking `iteratee` for each value
5
* in `collection` to generate the criterion by which the value is ranked.
6
* The `iteratee` is invoked with three arguments: (value, index|key, collection).
7
*
8
* @private
9
* @param {Array|Object|string} collection The collection to iterate over.
10
* @param {Function} iteratee The function invoked per iteration.
11
* @param {Function} comparator The function used to compare values.
12
* @param {*} exValue The initial extremum value.
13
* @returns {*} Returns the extremum value.
14
*/
15
function baseExtremum(collection, iteratee, comparator, exValue) {
16
var computed = exValue,
17
result = computed;
18
19
baseEach(collection, function(value, index, collection) {
20
var current = +iteratee(value, index, collection);
21
if (comparator(current, computed) || (current === exValue && current === result)) {
22
computed = current;
23
result = value;
24
}
25
});
26
return result;
27
}
28
29
module.exports = baseExtremum;
30
31