mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-01 07:47:49 +00:00
Add _.zipWith.
This commit is contained in:
@@ -6061,6 +6061,28 @@
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Combines elements of given arrays, like `_.zip` but with a function
|
||||
* specifying how they should be combined.
|
||||
*
|
||||
* @static
|
||||
* @memberOf _
|
||||
* @category Array
|
||||
* @param {...Array} [arrays] Arrays to be zipped with accumulator.
|
||||
* @param {Function} accumulator Function used to reduce zipped elements.
|
||||
* @returns {Array} Returns new array of accumulated groups.
|
||||
* @example
|
||||
*
|
||||
* _.zipWith([1, 2, 3], [10, 20 , 30], _.add);
|
||||
* // => [11, 22, 33]
|
||||
*/
|
||||
var zipWith = restParam(function(arrays) {
|
||||
var iteratee = arrays.pop();
|
||||
return arrayMap(unzip(arrays), function(array) {
|
||||
return arrayReduce(array, iteratee, undefined, true);
|
||||
});
|
||||
});
|
||||
|
||||
/*------------------------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
@@ -12009,6 +12031,7 @@
|
||||
lodash.xor = xor;
|
||||
lodash.zip = zip;
|
||||
lodash.zipObject = zipObject;
|
||||
lodash.zipWith = zipWith;
|
||||
|
||||
// Add aliases.
|
||||
lodash.backflow = flowRight;
|
||||
|
||||
16
test/test.js
16
test/test.js
@@ -16718,6 +16718,20 @@
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
QUnit.module('lodash.zipWith');
|
||||
|
||||
(function() {
|
||||
test('should combine values in lists with given function', 2, function() {
|
||||
var array1 = [1, 2, 3],
|
||||
array2 = [1, 2, 3];
|
||||
|
||||
deepEqual(_.zipWith(array1, array2, _.add), [2, 4, 6]);
|
||||
deepEqual(_.zipWith(array1, [], _.add), [1, 2, 3]);
|
||||
});
|
||||
}())
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
QUnit.module('lodash(...).commit');
|
||||
|
||||
(function() {
|
||||
@@ -17516,7 +17530,7 @@
|
||||
|
||||
var acceptFalsey = _.difference(allMethods, rejectFalsey);
|
||||
|
||||
test('should accept falsey arguments', 218, function() {
|
||||
test('should accept falsey arguments', 219, function() {
|
||||
var emptyArrays = _.map(falsey, _.constant([])),
|
||||
isExposed = '_' in root,
|
||||
oldDash = root._;
|
||||
|
||||
Reference in New Issue
Block a user