Ohm-Management - Projektarbeit B-ME
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

unzipWith.js 1.0KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. var apply = require('./_apply'),
  2. arrayMap = require('./_arrayMap'),
  3. unzip = require('./unzip');
  4. /**
  5. * This method is like `_.unzip` except that it accepts `iteratee` to specify
  6. * how regrouped 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} array The array of grouped elements to process.
  14. * @param {Function} [iteratee=_.identity] The function to combine
  15. * regrouped values.
  16. * @returns {Array} Returns the new array of regrouped elements.
  17. * @example
  18. *
  19. * var zipped = _.zip([1, 2], [10, 20], [100, 200]);
  20. * // => [[1, 10, 100], [2, 20, 200]]
  21. *
  22. * _.unzipWith(zipped, _.add);
  23. * // => [3, 30, 300]
  24. */
  25. function unzipWith(array, iteratee) {
  26. if (!(array && array.length)) {
  27. return [];
  28. }
  29. var result = unzip(array);
  30. if (iteratee == null) {
  31. return result;
  32. }
  33. return arrayMap(result, function(group) {
  34. return apply(iteratee, undefined, group);
  35. });
  36. }
  37. module.exports = unzipWith;