unzip.js 475 B

1234567891011121314151617
  1. var max = require('./max.js');
  2. var _getLength = require('./_getLength.js');
  3. var pluck = require('./pluck.js');
  4. // Complement of zip. Unzip accepts an array of arrays and groups
  5. // each array's elements on shared indices.
  6. function unzip(array) {
  7. var length = array && max(array, _getLength).length || 0;
  8. var result = Array(length);
  9. for (var index = 0; index < length; index++) {
  10. result[index] = pluck(array, index);
  11. }
  12. return result;
  13. }
  14. module.exports = unzip;