UNPKG

935 BJavaScriptView Raw
1import rest from './rest';
2import unzipWith from './unzipWith';
3
4/**
5 * This method is like `_.zip` except that it accepts `iteratee` to specify
6 * how grouped values should be combined. The iteratee is invoked with the
7 * elements of each group: (...group).
8 *
9 * @static
10 * @memberOf _
11 * @since 3.8.0
12 * @category Array
13 * @param {...Array} [arrays] The arrays to process.
14 * @param {Function} [iteratee=_.identity] The function to combine grouped values.
15 * @returns {Array} Returns the new array of grouped elements.
16 * @example
17 *
18 * _.zipWith([1, 2], [10, 20], [100, 200], function(a, b, c) {
19 * return a + b + c;
20 * });
21 * // => [111, 222]
22 */
23var zipWith = rest(function(arrays) {
24 var length = arrays.length,
25 iteratee = length > 1 ? arrays[length - 1] : undefined;
26
27 iteratee = typeof iteratee == 'function' ? (arrays.pop(), iteratee) : undefined;
28 return unzipWith(arrays, iteratee);
29});
30
31export default zipWith;