createArrayList = function(args){
        var array = [];
        for (var i = 0; i < args[0]; i++){
          array[i] = (args.length > 1 ? createArrayList(args.slice(1)) : 0 );
        }

        array.get = function(i) {
          return this[i];
        };
        array.contains = function(item) {
          return this.indexOf(item) !== -1;
        };
        array.add = function() {
          if(arguments.length === 1) {
            this.push(arguments[0]); // for add(Object)
          } else if(arguments.length === 2) {
            if (typeof arguments[0] === 'number') {
              if (arguments[0] >= 0 && arguments[0] <= this.length) { 
                this.splice(arguments[0], 0, arguments[1]); // for add(i, Object)
              } else {
                throw(arguments[0] + " is not a valid index");
              }
            } else {
              throw(typeof arguments[0] + " is not a number");
            }
          } else {
            throw("Please use the proper number of parameters.");
          }
        };
        array.set = function() {
          if(arguments.length === 2) {
            if (typeof arguments[0] === 'number') {
              if (arguments[0] >= 0 && arguments[0] < this.length) {
                this.splice(arguments[0], 1, arguments[1]);
              } else {
                throw(arguments[0] + " is not a valid index.");
              }
            } else {
              throw(typeof arguments[0] + " is not a number");
            }
          } else {
            throw("Please use the proper number of parameters.");
          }
        };
        array.size = function() {
          return this.length;
        };
        array.clear = function() {
          this.length = 0;
        };
        array.remove = function(i) {
          return this.splice(i, 1)[0];
        };
        array.isEmpty = function() {
          return !!this.length;
        };
        array.clone = function() {
          return this.slice(0);
        };
        array.toArray = function() {
          return this.slice(0);
        };

        return array;
      }
splice inserts "value" which can be either a scalar or an array 
      into "array" at position "index".