@newdash/newdash
Version:
javascript/typescript utility library
45 lines (44 loc) • 1.63 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const baseProperty_1 = __importDefault(require("./.internal/baseProperty"));
const isArrayLikeObject_1 = __importDefault(require("./isArrayLikeObject"));
const arrayFilter_1 = __importDefault(require("./.internal/arrayFilter"));
const baseTimes_1 = __importDefault(require("./.internal/baseTimes"));
const arrayMap_1 = __importDefault(require("./.internal/arrayMap"));
/**
* This method is like `zip` except that it accepts an array of grouped
* elements and creates an array regrouping the elements to their pre-zip
* configuration.
*
* @since 5.3.0
* @category Array
* @param array The array of grouped elements to process.
* @returns Returns the new array of regrouped elements.
* @see unzipWith,zip,zipObject,zipObjectDeep,zipWith
* @example
*
* ```js
* const zipped = zip(['a', 'b'], [1, 2], [true, false])
* // => [['a', 1, true], ['b', 2, false]]
*
* unzip(zipped)
* // => [['a', 'b'], [1, 2], [true, false]]
* ```
*/
function unzip(array) {
if (!(array && array.length)) {
return [];
}
let length = 0;
array = (0, arrayFilter_1.default)(array, (group) => {
if ((0, isArrayLikeObject_1.default)(group)) {
length = Math.max(group.length, length);
return true;
}
});
return (0, baseTimes_1.default)(length, (index) => (0, arrayMap_1.default)(array, (0, baseProperty_1.default)(index)));
}
exports.default = unzip;