mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-01 23:57:49 +00:00
Bump to v3.6.0.
This commit is contained in:
10
math/max.js
10
math/max.js
@@ -6,16 +6,16 @@ import createExtremum from '../internal/createExtremum';
|
||||
* `-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).
|
||||
* arguments: (value, index, collection).
|
||||
*
|
||||
* If a property name is provided for `predicate` the created `_.property`
|
||||
* 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 `predicate` the created `_.matches` style
|
||||
* 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`.
|
||||
*
|
||||
@@ -42,11 +42,11 @@ import createExtremum from '../internal/createExtremum';
|
||||
* _.max(users, function(chr) {
|
||||
* return chr.age;
|
||||
* });
|
||||
* // => { 'user': 'fred', 'age': 40 };
|
||||
* // => { 'user': 'fred', 'age': 40 }
|
||||
*
|
||||
* // using the `_.property` callback shorthand
|
||||
* _.max(users, 'age');
|
||||
* // => { 'user': 'fred', 'age': 40 };
|
||||
* // => { 'user': 'fred', 'age': 40 }
|
||||
*/
|
||||
var max = createExtremum(arrayMax);
|
||||
|
||||
|
||||
10
math/min.js
10
math/min.js
@@ -6,16 +6,16 @@ import createExtremum from '../internal/createExtremum';
|
||||
* `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).
|
||||
* arguments: (value, index, collection).
|
||||
*
|
||||
* If a property name is provided for `predicate` the created `_.property`
|
||||
* 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 `predicate` the created `_.matches` style
|
||||
* 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`.
|
||||
*
|
||||
@@ -42,11 +42,11 @@ import createExtremum from '../internal/createExtremum';
|
||||
* _.min(users, function(chr) {
|
||||
* return chr.age;
|
||||
* });
|
||||
* // => { 'user': 'barney', 'age': 36 };
|
||||
* // => { 'user': 'barney', 'age': 36 }
|
||||
*
|
||||
* // using the `_.property` callback shorthand
|
||||
* _.min(users, 'age');
|
||||
* // => { 'user': 'barney', 'age': 36 };
|
||||
* // => { 'user': 'barney', 'age': 36 }
|
||||
*/
|
||||
var min = createExtremum(arrayMin, true);
|
||||
|
||||
|
||||
45
math/sum.js
45
math/sum.js
@@ -1,4 +1,8 @@
|
||||
import arraySum from '../internal/arraySum';
|
||||
import baseCallback from '../internal/baseCallback';
|
||||
import baseSum from '../internal/baseSum';
|
||||
import isArray from '../lang/isArray';
|
||||
import isIterateeCall from '../internal/isIterateeCall';
|
||||
import toIterable from '../internal/toIterable';
|
||||
|
||||
/**
|
||||
@@ -8,26 +12,41 @@ import toIterable from '../internal/toIterable';
|
||||
* @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`.
|
||||
* @returns {number} Returns the sum.
|
||||
* @example
|
||||
*
|
||||
* _.sum([4, 6, 2]);
|
||||
* // => 12
|
||||
* _.sum([4, 6]);
|
||||
* // => 10
|
||||
*
|
||||
* _.sum({ 'a': 4, 'b': 6, 'c': 2 });
|
||||
* // => 12
|
||||
* _.sum({ 'a': 4, 'b': 6 });
|
||||
* // => 10
|
||||
*
|
||||
* var objects = [
|
||||
* { 'n': 4 },
|
||||
* { 'n': 6 }
|
||||
* ];
|
||||
*
|
||||
* _.sum(objects, function(object) {
|
||||
* return object.n;
|
||||
* });
|
||||
* // => 10
|
||||
*
|
||||
* // using the `_.property` callback shorthand
|
||||
* _.sum(objects, 'n');
|
||||
* // => 10
|
||||
*/
|
||||
function sum(collection) {
|
||||
if (!isArray(collection)) {
|
||||
collection = toIterable(collection);
|
||||
function sum(collection, iteratee, thisArg) {
|
||||
if (thisArg && isIterateeCall(collection, iteratee, thisArg)) {
|
||||
iteratee = null;
|
||||
}
|
||||
var length = collection.length,
|
||||
result = 0;
|
||||
var noIteratee = iteratee == null;
|
||||
|
||||
while (length--) {
|
||||
result += +collection[length] || 0;
|
||||
}
|
||||
return result;
|
||||
iteratee = noIteratee ? iteratee : baseCallback(iteratee, thisArg, 3);
|
||||
return noIteratee
|
||||
? arraySum(isArray(collection) ? collection : toIterable(collection))
|
||||
: baseSum(collection, iteratee);
|
||||
}
|
||||
|
||||
export default sum;
|
||||
|
||||
Reference in New Issue
Block a user