Python to Javascript
<pre><code>&gt;&gt;&gt; def clockwise(r):
...     return list(r[0]) + clockwise(list(reversed(zip(*r[1:])))) if r else []
... 
&gt;&gt;&gt; a = [ 
...   [ 1,  2,  3], 
...   [ 5,  6,  7], 
...   [ 9, 10, 11]]
&gt;&gt;&gt; clockwise(a)
[1, 2, 3, 7, 11, 10, 9, 5, 6]
</code></pre>

<p>I'm trying to change the function clockwise into Javascript but can't seem to get it to work.</p>

<p>I've created some methods with similar functions:</p>

<pre><code>function zip(masterArray){//zips 2 arrays
var innerLoop = masterArray.length; //inner loop
var outerLoop = 0;
//get length of shortest
for (var i = 0; i&lt;masterArray.length;i++){
    var a = masterArray[i].length;
    if (outerLoop==0){outerLoop = a;}else if(a &lt; outerLoop){outerLoop = a;}
}

var newOuterArray = new Array(outerLoop);
    for (var x = 0; x&lt;outerLoop;x++){
        var newInnerArray = new Array(innerLoop);
            for (var y = 0; y&lt;innerLoop;y++){
                newInnerArray[y] = masterArray[y][x];
                }
            newOuterArray[x] = newInnerArray;
}
 return newOuterArray;
}

function reversed(arr){
    var newArray = new Array(arr.length);
    var n = 0;
    for(var i=arr.length-1; i&gt;=0; i--){
        newArray[n++] = arr[i];
    }
    return newArray;
}

function clockwise(r){

    if(r.length&gt;0){
            var a = reversed(zip(r.slice(1)));
            a.splice(0,0,r[0]);
            return clockwise(a);
     }else{
        return [];
    }
}
</code></pre>

<p>Here's my progress. I'm stuck at the last part: clockwise error in firebug is too much recursion. </p>
