min
优质
小牛编辑
146浏览
2023-12-01
Gets the minimum value in the sequence.
Signature
Sequence.min = function(valueFn) { /*...*/ }
Sequence.min = function min(valueFn) { if (typeof valueFn !== "undefined") { return this.minBy(valueFn); } return this.reduce(function(prev, current, i) { if (typeof prev === "undefined") { return current; } return current < prev ? current : prev; }); }
Name | Type(s) | Description |
---|---|---|
valueFn | Function? | The function by which the value for comparison is calculated for each element in the sequence. |
returns | * | The element with the lowest value in the sequence, or undefined` if the sequence is empty. |
Examples
function negate(x) { return x * -1; } Lazy([]).min() // => undefined Lazy([1]).min() // => 1 Lazy([1, 2]).min() // => 1 Lazy([2, 1]).min() // => 1 Lazy([6, 18, 2, 49, 34]).min() // => 2 Lazy([6, 18, 2, 49, 34]).min(negate) // => 49 Lazy(['b', 'a', 'c']).min() // => 'a'