zipWith.js 960 B

123456789101112131415161718192021222324252627282930313233
  1. var baseRest = require('./_baseRest'),
  2. unzipWith = require('./unzipWith');
  3. /**
  4. * This method is like `_.zip` except that it accepts `iteratee` to specify
  5. * how grouped values should be combined. The iteratee is invoked with the
  6. * elements of each group: (...group).
  7. *
  8. * @static
  9. * @memberOf _
  10. * @since 3.8.0
  11. * @category Array
  12. * @param {...Array} [arrays] The arrays to process.
  13. * @param {Function} [iteratee=_.identity] The function to combine
  14. * 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. */
  23. var zipWith = baseRest(function(arrays) {
  24. var length = arrays.length,
  25. iteratee = length > 1 ? arrays[length - 1] : undefined;
  26. iteratee = typeof iteratee == 'function' ? (arrays.pop(), iteratee) : undefined;
  27. return unzipWith(arrays, iteratee);
  28. });
  29. module.exports = zipWith;