diff options
Diffstat (limited to 'tools/eslint/node_modules/lodash/unzip.js')
-rw-r--r-- | tools/eslint/node_modules/lodash/unzip.js | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/tools/eslint/node_modules/lodash/unzip.js b/tools/eslint/node_modules/lodash/unzip.js new file mode 100644 index 0000000000..0dddd4447b --- /dev/null +++ b/tools/eslint/node_modules/lodash/unzip.js @@ -0,0 +1,44 @@ +var arrayFilter = require('./_arrayFilter'), + arrayMap = require('./_arrayMap'), + baseProperty = require('./_baseProperty'), + baseTimes = require('./_baseTimes'), + isArrayLikeObject = require('./isArrayLikeObject'); + +/* Built-in method references for those with the same name as other `lodash` methods. */ +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 []; + } + var length = 0; + array = arrayFilter(array, function(group) { + if (isArrayLikeObject(group)) { + length = nativeMax(group.length, length); + return true; + } + }); + return baseTimes(length, function(index) { + return arrayMap(array, baseProperty(index)); + }); +} + +module.exports = unzip; |