lodash.reduce
Advanced tools
Comparing version 3.0.0 to 3.0.1
46
index.js
/** | ||
* lodash 3.0.0 (Custom Build) <https://lodash.com/> | ||
* lodash 3.0.1 (Custom Build) <https://lodash.com/> | ||
* Build: `lodash modern modularize exports="npm" -o ./` | ||
* Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/> | ||
* Based on Underscore.js 1.7.0 <http://underscorejs.org/LICENSE> | ||
* Based on Underscore.js 1.8.2 <http://underscorejs.org/LICENSE> | ||
* Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors | ||
@@ -16,3 +16,3 @@ * Available under MIT license <https://lodash.com/license> | ||
* A specialized version of `_.reduce` for arrays without support for callback | ||
* shorthands or `this` binding. | ||
* shorthands and `this` binding. | ||
* | ||
@@ -41,2 +41,19 @@ * @private | ||
/** | ||
* Creates a function for `_.reduce` or `_.reduceRight`. | ||
* | ||
* @private | ||
* @param {Function} arrayFunc The function to iterate over an array. | ||
* @param {Function} eachFunc The function to iterate over a collection. | ||
* @returns {Function} Returns the new each function. | ||
*/ | ||
function createReduce(arrayFunc, eachFunc) { | ||
return function(collection, iteratee, accumulator, thisArg) { | ||
var initFromArray = arguments.length < 3; | ||
return (typeof iteratee == 'function' && typeof thisArg == 'undefined' && isArray(collection)) | ||
? arrayFunc(collection, iteratee, accumulator, initFromArray) | ||
: baseReduce(collection, baseCallback(iteratee, thisArg, 4), accumulator, initFromArray, eachFunc); | ||
}; | ||
} | ||
/** | ||
* Reduces `collection` to a value which is the accumulated result of running | ||
@@ -46,5 +63,11 @@ * each element in `collection` through `iteratee`, where each successive | ||
* is not provided the first element of `collection` is used as the initial | ||
* value. The `iteratee` is bound to `thisArg`and invoked with four arguments; | ||
* value. The `iteratee` is bound to `thisArg` and invoked with four arguments: | ||
* (accumulator, value, index|key, collection). | ||
* | ||
* Many lodash methods are guarded to work as interatees for methods like | ||
* `_.reduce`, `_.reduceRight`, and `_.transform`. | ||
* | ||
* The guarded methods are: | ||
* `assign`, `defaults`, `includes`, `merge`, `sortByAll`, and `sortByOrder` | ||
* | ||
* @static | ||
@@ -61,16 +84,15 @@ * @memberOf _ | ||
* | ||
* var sum = _.reduce([1, 2, 3], function(sum, n) { return sum + n; }); | ||
* // => 6 | ||
* _.reduce([1, 2], function(sum, n) { | ||
* return sum + n; | ||
* }); | ||
* // => 3 | ||
* | ||
* var mapped = _.reduce({ 'a': 1, 'b': 2, 'c': 3 }, function(result, n, key) { | ||
* _.reduce({ 'a': 1, 'b': 2 }, function(result, n, key) { | ||
* result[key] = n * 3; | ||
* return result; | ||
* }, {}); | ||
* // => { 'a': 3, 'b': 6, 'c': 9 } (iteration order is not guaranteed) | ||
* // => { 'a': 3, 'b': 6 } (iteration order is not guaranteed) | ||
*/ | ||
function reduce(collection, iteratee, accumulator, thisArg) { | ||
var func = isArray(collection) ? arrayReduce : baseReduce; | ||
return func(collection, baseCallback(iteratee, thisArg, 4), accumulator, arguments.length < 3, baseEach); | ||
} | ||
var reduce = createReduce(arrayReduce, baseEach); | ||
module.exports = reduce; |
Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/> | ||
Based on Underscore.js 1.7.0, copyright 2009-2015 Jeremy Ashkenas, | ||
Based on Underscore.js, copyright 2009-2015 Jeremy Ashkenas, | ||
DocumentCloud and Investigative Reporters & Editors <http://underscorejs.org/> | ||
@@ -4,0 +4,0 @@ |
{ | ||
"name": "lodash.reduce", | ||
"version": "3.0.0", | ||
"version": "3.0.1", | ||
"description": "The modern build of lodash’s `_.reduce` as a module.", | ||
@@ -5,0 +5,0 @@ "homepage": "https://lodash.com/", |
@@ -1,2 +0,2 @@ | ||
# lodash.reduce v3.0.0 | ||
# lodash.reduce v3.0.1 | ||
@@ -20,2 +20,2 @@ The [modern build](https://github.com/lodash/lodash/wiki/Build-Differences) of [lodash’s](https://lodash.com/) `_.reduce` exported as a [Node.js](http://nodejs.org/)/[io.js](https://iojs.org/) module. | ||
See the [documentation](https://lodash.com/docs#reduce) or [package source](https://github.com/lodash/lodash/blob/3.0.0-npm-packages/lodash.reduce) for more details. | ||
See the [documentation](https://lodash.com/docs#reduce) or [package source](https://github.com/lodash/lodash/blob/3.0.1-npm-packages/lodash.reduce) for more details. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6333
89