UNPKG

517 BJavaScriptView Raw
1var pluck = require('./pluck')
2
3var max = require('./max')
4
5/**
6 * 与 zip 相反
7 *
8 * @param {Array} arrays 数组集合
9 */
10function unzip (arrays) {
11 var index, maxItem, len
12 var result = []
13 if (arrays && arrays.length) {
14 index = 0
15 maxItem = max(arrays, function (item) {
16 return item ? item.length : 0
17 })
18 for (len = maxItem ? maxItem.length : 0; index < len; index++) {
19 result.push(pluck(arrays, index))
20 }
21 }
22 return result
23}
24
25module.exports = unzip