Initial commit
[yaffs-website] / node_modules / grunt-contrib-watch / node_modules / lodash / array / unzip.js
1 var arrayFilter = require('../internal/arrayFilter'),
2     arrayMap = require('../internal/arrayMap'),
3     baseProperty = require('../internal/baseProperty'),
4     isArrayLike = require('../internal/isArrayLike');
5
6 /* Native method references for those with the same name as other `lodash` methods. */
7 var nativeMax = Math.max;
8
9 /**
10  * This method is like `_.zip` except that it accepts an array of grouped
11  * elements and creates an array regrouping the elements to their pre-zip
12  * configuration.
13  *
14  * @static
15  * @memberOf _
16  * @category Array
17  * @param {Array} array The array of grouped elements to process.
18  * @returns {Array} Returns the new array of regrouped elements.
19  * @example
20  *
21  * var zipped = _.zip(['fred', 'barney'], [30, 40], [true, false]);
22  * // => [['fred', 30, true], ['barney', 40, false]]
23  *
24  * _.unzip(zipped);
25  * // => [['fred', 'barney'], [30, 40], [true, false]]
26  */
27 function unzip(array) {
28   if (!(array && array.length)) {
29     return [];
30   }
31   var index = -1,
32       length = 0;
33
34   array = arrayFilter(array, function(group) {
35     if (isArrayLike(group)) {
36       length = nativeMax(group.length, length);
37       return true;
38     }
39   });
40   var result = Array(length);
41   while (++index < length) {
42     result[index] = arrayMap(array, baseProperty(index));
43   }
44   return result;
45 }
46
47 module.exports = unzip;