mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-06 01:47:48 +00:00
Consolidate max and min modules.
This commit is contained in:
24
min.js
24
min.js
@@ -1,6 +1,4 @@
|
||||
import baseExtremum from './.internal/baseExtremum.js';
|
||||
import baseLt from './.internal/baseLt.js';
|
||||
import identity from './identity.js';
|
||||
import isSymbol from './isSymbol.js';
|
||||
|
||||
/**
|
||||
* Computes the minimum value of `array`. If `array` is empty or falsey,
|
||||
@@ -19,9 +17,23 @@ import identity from './identity.js';
|
||||
* // => undefined
|
||||
*/
|
||||
function min(array) {
|
||||
return (array && array.length)
|
||||
? baseExtremum(array, identity, baseLt)
|
||||
: undefined;
|
||||
let result;
|
||||
let index = -1;
|
||||
const length = array ? array.length : 0;
|
||||
|
||||
while (++index < length) {
|
||||
let computed;
|
||||
const value = array[index];
|
||||
|
||||
if (value != null && (computed === undefined
|
||||
? (value === value && !isSymbol(value))
|
||||
: (value < computed)
|
||||
)) {
|
||||
computed = value;
|
||||
result = value;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
export default min;
|
||||
|
||||
Reference in New Issue
Block a user