Debian Codegraph @

dojox/lang/functional/zip.js

raw symbols SCIP
1 define(["dojo/_base/lang", "./lambda"],
2 function(lang, df){
3
4 // This module adds high-level functions and related constructs:
5 // - zip combiners
6
7 // Defined methods:
8 // - operate on dense arrays
9
10 lang.mixin(df, {
11 // combiners
12 zip: function(){
13 // summary:
14 // returns an array of arrays, where the i-th array
15 // contains the i-th element from each of the argument arrays.
16 // description:
17 // This is the venerable zip combiner (for example,
18 // see Python documentation for general details). The returned
19 // array is truncated to match the length of the shortest input
20 // array.
21 var n = arguments[0].length, m = arguments.length, i = 1, t = new Array(n), j, p;
22 for(; i < m; n = Math.min(n, arguments[i++].length));
23 for(i = 0; i < n; ++i){
24 p = new Array(m);
25 for(j = 0; j < m; p[j] = arguments[j][i], ++j);
26 t[i] = p;
27 }
28 return t; // Array
29 },
30 unzip: function(/*Array*/ a){
31 // summary:
32 // similar to dojox.lang.functional.zip(), but takes
33 // a single array of arrays as the input.
34 // description:
35 // This function is similar to dojox.lang.functional.zip()
36 // and can be used to unzip objects packed by
37 // dojox.lang.functional.zip(). It is here mostly to provide
38 // a short-cut for the different method signature.
39 return df.zip.apply(null, a); // Array
40 }
41 });
42 });