main
Last change
on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago |
Update repo after prototype presentation
|
-
Property mode
set to
100644
|
File size:
1.0 KB
|
Rev | Line | |
---|
[d565449] | 1 | import apply from './_apply.js';
|
---|
| 2 | import arrayMap from './_arrayMap.js';
|
---|
| 3 | import unzip from './unzip.js';
|
---|
| 4 |
|
---|
| 5 | /**
|
---|
| 6 | * This method is like `_.unzip` except that it accepts `iteratee` to specify
|
---|
| 7 | * how regrouped values should be combined. The iteratee is invoked with the
|
---|
| 8 | * elements of each group: (...group).
|
---|
| 9 | *
|
---|
| 10 | * @static
|
---|
| 11 | * @memberOf _
|
---|
| 12 | * @since 3.8.0
|
---|
| 13 | * @category Array
|
---|
| 14 | * @param {Array} array The array of grouped elements to process.
|
---|
| 15 | * @param {Function} [iteratee=_.identity] The function to combine
|
---|
| 16 | * regrouped values.
|
---|
| 17 | * @returns {Array} Returns the new array of regrouped elements.
|
---|
| 18 | * @example
|
---|
| 19 | *
|
---|
| 20 | * var zipped = _.zip([1, 2], [10, 20], [100, 200]);
|
---|
| 21 | * // => [[1, 10, 100], [2, 20, 200]]
|
---|
| 22 | *
|
---|
| 23 | * _.unzipWith(zipped, _.add);
|
---|
| 24 | * // => [3, 30, 300]
|
---|
| 25 | */
|
---|
| 26 | function unzipWith(array, iteratee) {
|
---|
| 27 | if (!(array && array.length)) {
|
---|
| 28 | return [];
|
---|
| 29 | }
|
---|
| 30 | var result = unzip(array);
|
---|
| 31 | if (iteratee == null) {
|
---|
| 32 | return result;
|
---|
| 33 | }
|
---|
| 34 | return arrayMap(result, function(group) {
|
---|
| 35 | return apply(iteratee, undefined, group);
|
---|
| 36 | });
|
---|
| 37 | }
|
---|
| 38 |
|
---|
| 39 | export default unzipWith;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.