Consolidate max and min modules.

This commit is contained in:
John-David Dalton
2017-01-11 00:03:28 -08:00
parent 6c54ae2ae5
commit 401c0f053c
5 changed files with 74 additions and 56 deletions

24
max.js
View File

@@ -1,6 +1,4 @@
import baseExtremum from './.internal/baseExtremum.js';
import baseGt from './.internal/baseGt.js';
import identity from './identity.js';
import isSymbol from './isSymbol.js';
/**
* Computes the maximum value of `array`. If `array` is empty or falsey,
@@ -19,9 +17,23 @@ import identity from './identity.js';
* // => undefined
*/
function max(array) {
return (array && array.length)
? baseExtremum(array, identity, baseGt)
: 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 max;