forked from lodash/lodash
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathunzipWith.js
31 lines (29 loc) · 882 Bytes
/
unzipWith.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import map from './map.js'
import unzip from './unzip.js'
/**
* This method is like `unzip` except that it accepts `iteratee` to specify
* how regrouped values should be combined. The iteratee is invoked with the
* elements of each group: (...group).
*
* @since 3.8.0
* @category Array
* @param {Array} array The array of grouped elements to process.
* @param {Function} iteratee The function to combine
* regrouped values.
* @returns {Array} Returns the new array of regrouped elements.
* @example
*
* const zipped = zip([1, 2], [10, 20], [100, 200])
* // => [[1, 10, 100], [2, 20, 200]]
*
* unzipWith(zipped, add)
* // => [3, 30, 300]
*/
function unzipWith(array, iteratee) {
if (!(array != null && array.length)) {
return []
}
const result = unzip(array)
return map(result, (group) => iteratee.apply(undefined, group))
}
export default unzipWith