Skip navigation.

My comments on ...

... everything bothering me

n-Dimensional Arrays

function nD(){
   var A,tempA; //final and temp array
   var dimension=arguments.length, i; //iteration vars
   while(dimension--){
      tempA = Array(arguments[dimension]);
      i = tempA.length;
      while(i--)
         tempA[i]=A;
      A = tempA;
   }
   return A;
};

function check(A){
   return (""+A).split(",").length;
};

var test = nD(3,3,3); //create 3x3x3 'cube'
alert(test);
alert(check(test))); //check 'volume'


Or the short version:
l='length';

function nD(){
   var a,b,c=arguments,d=c[l],i;
   while(d--){
      i = (b = Array(c[d]))[l];
      while(i--)
         b[i]=a;
      a = b;
   }
   return a;
};

function check(a){
   return (""+a).split(",")[l];
};

alert(nD(3,3,3));
alert(check(nD(3,3,3)));

Wrapping IE's DOM functionsSafari and HTMLElement.prototype

Write a comment

You must be logged in to write a comment. If you're not a registered member, please sign up.

December 2008
M T W T F S S
November 2008January 2009
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31