The Wayback Machine - https://web.archive.org/web/20201220222710/https://github.com/lodash/lodash/blob/master/unzipWith.js
Skip to content
Permalink
master
Go to file
 
 
Cannot retrieve contributors at this time
31 lines (29 sloc) 882 Bytes
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
You can’t perform that action at this time.