source: Dev/trunk/src/client/dojox/lang/functional/zip.js @ 529

Last change on this file since 529 was 483, checked in by hendrikvanantwerpen, 11 years ago

Added Dojo 1.9.3 release.

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