source: Dev/branches/rest-dojo-ui/client/dojox/lang/functional/zip.js @ 256

Last change on this file since 256 was 256, checked in by hendrikvanantwerpen, 13 years ago

Reworked project structure based on REST interaction and Dojo library. As
soon as this is stable, the old jQueryUI branch can be removed (it's
kept for reference).

  • Property svn:executable set to *
File size: 1.3 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: returns an array of arrays, where the i-th array
16                        //      contains the i-th element from each of the argument arrays.
17                        // description: 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: similar to dojox.lang.functional.zip(), but takes
32                        //      a single array of arrays as the input.
33                        // description: This function is similar to dojox.lang.functional.zip()
34                        //      and can be used to unzip objects packed by
35                        //      dojox.lang.functional.zip(). It is here mostly to provide
36                        //      a short-cut for the different method signature.
37                        return df.zip.apply(null, a);   // Array
38                }
39        });
40})();
Note: See TracBrowser for help on using the repository browser.