Initial commit
[yaffs-website] / node_modules / grunt-contrib-watch / node_modules / lodash / array / zipWith.js
1 var restParam = require('../function/restParam'),
2     unzipWith = require('./unzipWith');
3
4 /**
5  * This method is like `_.zip` except that it accepts an iteratee to specify
6  * how grouped values should be combined. The `iteratee` is bound to `thisArg`
7  * and invoked with four arguments: (accumulator, value, index, group).
8  *
9  * @static
10  * @memberOf _
11  * @category Array
12  * @param {...Array} [arrays] The arrays to process.
13  * @param {Function} [iteratee] The function to combine grouped values.
14  * @param {*} [thisArg] The `this` binding of `iteratee`.
15  * @returns {Array} Returns the new array of grouped elements.
16  * @example
17  *
18  * _.zipWith([1, 2], [10, 20], [100, 200], _.add);
19  * // => [111, 222]
20  */
21 var zipWith = restParam(function(arrays) {
22   var length = arrays.length,
23       iteratee = length > 2 ? arrays[length - 2] : undefined,
24       thisArg = length > 1 ? arrays[length - 1] : undefined;
25
26   if (length > 2 && typeof iteratee == 'function') {
27     length -= 2;
28   } else {
29     iteratee = (length > 1 && typeof thisArg == 'function') ? (--length, thisArg) : undefined;
30     thisArg = undefined;
31   }
32   arrays.length = length;
33   return unzipWith(arrays, iteratee, thisArg);
34 });
35
36 module.exports = zipWith;