5d28c9be6f9709198e5e28c5a402282fe43c43e1
[platform/framework/web/crosswalk-tizen.git] /
1 var arrayMap = require('../internal/arrayMap'),
2     arrayMax = require('../internal/arrayMax'),
3     baseProperty = require('../internal/baseProperty'),
4     getLength = require('../internal/getLength');
5
6 /**
7  * This method is like `_.zip` except that it accepts an array of grouped
8  * elements and creates an array regrouping the elements to their pre-`_.zip`
9  * configuration.
10  *
11  * @static
12  * @memberOf _
13  * @category Array
14  * @param {Array} array The array of grouped elements to process.
15  * @returns {Array} Returns the new array of regrouped elements.
16  * @example
17  *
18  * var zipped = _.zip(['fred', 'barney'], [30, 40], [true, false]);
19  * // => [['fred', 30, true], ['barney', 40, false]]
20  *
21  * _.unzip(zipped);
22  * // => [['fred', 'barney'], [30, 40], [true, false]]
23  */
24 function unzip(array) {
25   var index = -1,
26       length = (array && array.length && arrayMax(arrayMap(array, getLength))) >>> 0,
27       result = Array(length);
28
29   while (++index < length) {
30     result[index] = arrayMap(array, baseProperty(index));
31   }
32   return result;
33 }
34
35 module.exports = unzip;