Files
lodash/unzipWith.js
John-David Dalton 6cb3460fce Remove semicolons.
2017-02-05 22:22:04 -08:00

33 lines
939 B
JavaScript

import apply from './.internal/apply.js'
import arrayMap from './.internal/arrayMap.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 && array.length)) {
return []
}
const result = unzip(array)
return arrayMap(result, group => apply(iteratee, undefined, group))
}
export default unzipWith