@newdash/newdash
Version:
javascript/typescript utility library
43 lines (42 loc) • 1.32 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.unzipWith = void 0;
// @ts-nocheck
const unzip_1 = __importDefault(require("./unzip"));
const arrayMap_1 = __importDefault(require("./.internal/arrayMap"));
/**
* 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 5.7.0
* @category Array
* @param array The array of grouped elements to process.
* @param iteratee The function to combine
* regrouped values.
* @returns Returns the new array of regrouped elements.
* @example
*
* ```js
* 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 = (0, unzip_1.default)(array);
if (iteratee == null) {
return result;
}
return (0, arrayMap_1.default)(result, (group) => iteratee(...group));
}
exports.unzipWith = unzipWith;
exports.default = unzipWith;