mirror of https://github.com/lukechilds/node.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
1.3 KiB
45 lines
1.3 KiB
9 years ago
|
var arrayFilter = require('./_arrayFilter'),
|
||
|
arrayMap = require('./_arrayMap'),
|
||
|
baseProperty = require('./_baseProperty'),
|
||
|
baseTimes = require('./_baseTimes'),
|
||
|
isArrayLikeObject = require('./isArrayLikeObject');
|
||
10 years ago
|
|
||
9 years ago
|
/* Built-in method references for those with the same name as other `lodash` methods. */
|
||
10 years ago
|
var nativeMax = Math.max;
|
||
|
|
||
|
/**
|
||
|
* 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.
|
||
|
*
|
||
|
* @static
|
||
|
* @memberOf _
|
||
|
* @category Array
|
||
|
* @param {Array} array The array of grouped elements to process.
|
||
|
* @returns {Array} Returns the new array of regrouped elements.
|
||
|
* @example
|
||
|
*
|
||
|
* var zipped = _.zip(['fred', 'barney'], [30, 40], [true, false]);
|
||
|
* // => [['fred', 30, true], ['barney', 40, false]]
|
||
|
*
|
||
|
* _.unzip(zipped);
|
||
|
* // => [['fred', 'barney'], [30, 40], [true, false]]
|
||
|
*/
|
||
|
function unzip(array) {
|
||
|
if (!(array && array.length)) {
|
||
|
return [];
|
||
|
}
|
||
9 years ago
|
var length = 0;
|
||
10 years ago
|
array = arrayFilter(array, function(group) {
|
||
9 years ago
|
if (isArrayLikeObject(group)) {
|
||
10 years ago
|
length = nativeMax(group.length, length);
|
||
|
return true;
|
||
|
}
|
||
|
});
|
||
9 years ago
|
return baseTimes(length, function(index) {
|
||
|
return arrayMap(array, baseProperty(index));
|
||
|
});
|
||
10 years ago
|
}
|
||
|
|
||
|
module.exports = unzip;
|