UNPKG

662 BJavaScriptView Raw
1var max = require('./max');
2var map = require('./map');
3
4 function getLength(arr) {
5 return arr == null ? 0 : arr.length;
6 }
7
8 /**
9 * Merges together the values of each of the arrays with the values at the
10 * corresponding position.
11 */
12 function zip(arr){
13 var len = arr ? max(map(arguments, getLength)) : 0,
14 results = [],
15 i = -1;
16 while (++i < len) {
17 // jshint loopfunc: true
18 results.push(map(arguments, function(item) {
19 return item == null ? undefined : item[i];
20 }));
21 }
22
23 return results;
24 }
25
26 module.exports = zip;
27
28