unzip.js 492 B

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