lodash.max
Advanced tools
Comparing version
161
index.js
/** | ||
* lodash 3.4.0 (Custom Build) <https://lodash.com/> | ||
* Build: `lodash modern modularize exports="npm" -o ./` | ||
* Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/> | ||
* lodash 4.0.0 (Custom Build) <https://lodash.com/> | ||
* Build: `lodash modularize exports="npm" -o ./` | ||
* Copyright 2012-2016 The Dojo Foundation <http://dojofoundation.org/> | ||
* Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE> | ||
* Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors | ||
* Copyright 2009-2016 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors | ||
* Available under MIT license <https://lodash.com/license> | ||
*/ | ||
var baseCallback = require('lodash._basecallback'), | ||
baseEach = require('lodash._baseeach'), | ||
isIterateeCall = require('lodash._isiterateecall'), | ||
toIterable = require('lodash._toiterable'), | ||
gt = require('lodash.gt'), | ||
isArray = require('lodash.isarray'); | ||
/** Used as references for `-Infinity` and `Infinity`. */ | ||
var NEGATIVE_INFINITY = Number.NEGATIVE_INFINITY; | ||
/** | ||
* A specialized version of `baseExtremum` for arrays which invokes `iteratee` | ||
* with one argument: (value). | ||
* The base implementation of methods like `_.max` and `_.min` which accepts a | ||
* `comparator` to determine the extremum value. | ||
* | ||
* @private | ||
* @param {Array} array The array to iterate over. | ||
* @param {Function} iteratee The function invoked per iteration. | ||
* @param {Function} comparator The function used to compare values. | ||
* @param {*} exValue The initial extremum value. | ||
* @param {Function} iteratee The iteratee invoked per iteration. | ||
* @param {Function} comparator The comparator used to compare values. | ||
* @returns {*} Returns the extremum value. | ||
*/ | ||
function arrayExtremum(array, iteratee, comparator, exValue) { | ||
function baseExtremum(array, iteratee, comparator) { | ||
var index = -1, | ||
length = array.length, | ||
computed = exValue, | ||
result = computed; | ||
length = array.length; | ||
while (++index < length) { | ||
var value = array[index], | ||
current = +iteratee(value); | ||
current = iteratee(value); | ||
if (comparator(current, computed)) { | ||
computed = current; | ||
result = value; | ||
if (current != null && (computed === undefined | ||
? current === current | ||
: comparator(current, computed) | ||
)) { | ||
var computed = current, | ||
result = value; | ||
} | ||
@@ -49,76 +40,52 @@ } | ||
/** | ||
* Gets the extremum value of `collection` invoking `iteratee` for each value | ||
* in `collection` to generate the criterion by which the value is ranked. | ||
* The `iteratee` is invoked with three arguments: (value, index|key, collection). | ||
* Checks if `value` is greater than `other`. | ||
* | ||
* @private | ||
* @param {Array|Object|string} collection The collection to iterate over. | ||
* @param {Function} iteratee The function invoked per iteration. | ||
* @param {Function} comparator The function used to compare values. | ||
* @param {*} exValue The initial extremum value. | ||
* @returns {*} Returns the extremum value. | ||
* @static | ||
* @memberOf _ | ||
* @category Lang | ||
* @param {*} value The value to compare. | ||
* @param {*} other The other value to compare. | ||
* @returns {boolean} Returns `true` if `value` is greater than `other`, else `false`. | ||
* @example | ||
* | ||
* _.gt(3, 1); | ||
* // => true | ||
* | ||
* _.gt(3, 3); | ||
* // => false | ||
* | ||
* _.gt(1, 3); | ||
* // => false | ||
*/ | ||
function baseExtremum(collection, iteratee, comparator, exValue) { | ||
var computed = exValue, | ||
result = computed; | ||
baseEach(collection, function(value, index, collection) { | ||
var current = +iteratee(value, index, collection); | ||
if (comparator(current, computed) || (current === exValue && current === result)) { | ||
computed = current; | ||
result = value; | ||
} | ||
}); | ||
return result; | ||
function gt(value, other) { | ||
return value > other; | ||
} | ||
/** | ||
* Creates a `_.max` or `_.min` function. | ||
* This method returns the first argument provided to it. | ||
* | ||
* @private | ||
* @param {Function} comparator The function used to compare values. | ||
* @param {*} exValue The initial extremum value. | ||
* @returns {Function} Returns the new extremum function. | ||
* @static | ||
* @memberOf _ | ||
* @category Util | ||
* @param {*} value Any value. | ||
* @returns {*} Returns `value`. | ||
* @example | ||
* | ||
* var object = { 'user': 'fred' }; | ||
* | ||
* _.identity(object) === object; | ||
* // => true | ||
*/ | ||
function createExtremum(comparator, exValue) { | ||
return function(collection, iteratee, thisArg) { | ||
if (thisArg && isIterateeCall(collection, iteratee, thisArg)) { | ||
iteratee = undefined; | ||
} | ||
iteratee = baseCallback(iteratee, thisArg, 3); | ||
if (iteratee.length == 1) { | ||
collection = isArray(collection) ? collection : toIterable(collection); | ||
var result = arrayExtremum(collection, iteratee, comparator, exValue); | ||
if (!(collection.length && result === exValue)) { | ||
return result; | ||
} | ||
} | ||
return baseExtremum(collection, iteratee, comparator, exValue); | ||
}; | ||
function identity(value) { | ||
return value; | ||
} | ||
/** | ||
* Gets the maximum value of `collection`. If `collection` is empty or falsey | ||
* `-Infinity` is returned. If an iteratee function is provided it is invoked | ||
* for each value in `collection` to generate the criterion by which the value | ||
* is ranked. The `iteratee` is bound to `thisArg` and invoked with three | ||
* arguments: (value, index, collection). | ||
* Computes the maximum value of `array`. If `array` is empty or falsey | ||
* `undefined` is returned. | ||
* | ||
* If a property name is provided for `iteratee` the created `_.property` | ||
* style callback returns the property value of the given element. | ||
* | ||
* If a value is also provided for `thisArg` the created `_.matchesProperty` | ||
* style callback returns `true` for elements that have a matching property | ||
* value, else `false`. | ||
* | ||
* If an object is provided for `iteratee` the created `_.matches` style | ||
* callback returns `true` for elements that have the properties of the given | ||
* object, else `false`. | ||
* | ||
* @static | ||
* @memberOf _ | ||
* @category Math | ||
* @param {Array|Object|string} collection The collection to iterate over. | ||
* @param {Function|Object|string} [iteratee] The function invoked per iteration. | ||
* @param {*} [thisArg] The `this` binding of `iteratee`. | ||
* @param {Array} array The array to iterate over. | ||
* @returns {*} Returns the maximum value. | ||
@@ -131,20 +98,10 @@ * @example | ||
* _.max([]); | ||
* // => -Infinity | ||
* | ||
* var users = [ | ||
* { 'user': 'barney', 'age': 36 }, | ||
* { 'user': 'fred', 'age': 40 } | ||
* ]; | ||
* | ||
* _.max(users, function(chr) { | ||
* return chr.age; | ||
* }); | ||
* // => { 'user': 'fred', 'age': 40 } | ||
* | ||
* // using the `_.property` callback shorthand | ||
* _.max(users, 'age'); | ||
* // => { 'user': 'fred', 'age': 40 } | ||
* // => undefined | ||
*/ | ||
var max = createExtremum(gt, NEGATIVE_INFINITY); | ||
function max(array) { | ||
return (array && array.length) | ||
? baseExtremum(array, identity, gt) | ||
: undefined; | ||
} | ||
module.exports = max; |
{ | ||
"name": "lodash.max", | ||
"version": "3.4.0", | ||
"description": "The modern build of lodash’s `_.max` as a module.", | ||
"version": "4.0.0", | ||
"description": "The lodash method `_.max` exported as a module.", | ||
"homepage": "https://lodash.com/", | ||
"icon": "https://lodash.com/icon.svg", | ||
"license": "MIT", | ||
"keywords": "lodash, lodash-modularized, stdlib, util", | ||
"keywords": "lodash, lodash-modularized, stdlib, util, max", | ||
"author": "John-David Dalton <john.david.dalton@gmail.com> (http://allyoucanleet.com/)", | ||
"contributors": [ | ||
"John-David Dalton <john.david.dalton@gmail.com> (http://allyoucanleet.com/)", | ||
"Benjamin Tan <demoneaux@gmail.com> (https://d10.github.io/)", | ||
"Blaine Bublitz <blaine@iceddev.com> (http://www.iceddev.com/)", | ||
"Kit Cambridge <github@kitcambridge.be> (http://kitcambridge.be/)", | ||
"Blaine Bublitz <blaine@iceddev.com> (https://github.com/phated)", | ||
"Mathias Bynens <mathias@qiwi.be> (https://mathiasbynens.be/)" | ||
], | ||
"repository": "lodash/lodash", | ||
"scripts": { "test": "echo \"See https://travis-ci.org/lodash/lodash-cli for testing details.\"" }, | ||
"dependencies": { | ||
"lodash._basecallback": "^3.0.0", | ||
"lodash._baseeach": "^3.0.0", | ||
"lodash._isiterateecall": "^3.0.0", | ||
"lodash._toiterable": "^3.0.0", | ||
"lodash.gt": "^3.0.0", | ||
"lodash.isarray": "^3.0.0", | ||
"lodash.keys": "^3.0.0" | ||
} | ||
"scripts": { "test": "echo \"See https://travis-ci.org/lodash/lodash-cli for testing details.\"" } | ||
} |
@@ -1,4 +0,4 @@ | ||
# lodash.max v3.4.0 | ||
# lodash.max v4.0.0 | ||
The [modern build](https://github.com/lodash/lodash/wiki/Build-Differences) of [lodash’s](https://lodash.com/) `_.max` exported as a [Node.js](http://nodejs.org/)/[io.js](https://iojs.org/) module. | ||
The [lodash](https://lodash.com/) method `_.max` exported as a [Node.js](https://nodejs.org/) module. | ||
@@ -8,3 +8,2 @@ ## Installation | ||
Using npm: | ||
```bash | ||
@@ -15,4 +14,3 @@ $ {sudo -H} npm i -g npm | ||
In Node.js/io.js: | ||
In Node.js: | ||
```js | ||
@@ -22,2 +20,2 @@ var max = require('lodash.max'); | ||
See the [documentation](https://lodash.com/docs#max) or [package source](https://github.com/lodash/lodash/blob/3.4.0-npm-packages/lodash.max) for more details. | ||
See the [documentation](https://lodash.com/docs#max) or [package source](https://github.com/lodash/lodash/blob/4.0.0-npm-packages/lodash.max) for more details. |
Sorry, the diff of this file is not supported yet
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
0
-100%2
-33.33%4860
-38.89%98
-29.5%19
-9.52%- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed