Array.prototype.minR = function() {//
//
/*this.sort(function (a, b) {
return random(2)>0 ? 1 : -1;
});*/
x = this[0];
k = 0;
for (i=1; i<this.Length; i++) {
y = this[i];
if (y<x) {
x = y;
k = i;
}
}
this[k] = this[this.length-1];
this.length--;
return x;
};
a = [1, 3, 4, 5];
trace(a.minR());
trace(a);
Array.prototype.del = function(i) {//刪除第i個元素
x = this[i-1];
for (j=i-1; j<this.length-1; j++) {
this[j] = this[j+1];
this.length--;
return x;
}
};
//a.del(0);
//trace(a);
Array.prototype.insert = function(i, x) {//從第i個位置插入x
for (j=this.length-1; j>=i-1; j--) {
this[j+1] = this[j];
}
this[i-1] = x;
//this.length++;
};
a.insert(2, 10000000);
//trace(a);
Array.prototype.delX = function(x) {
//從數組中刪除具有給定直的X的所有元素
i = 0;
while (i<this.length) {
if (this[i] == x) {
for (j=i+1; j<this.length; j++) {
this[j-1] = this[j];
}
this.length--;
} else {
i++;
}
}
};
b = [0, 0, 1, 2, 3, 4,5,5];
b.delX(0);
trace(b);
Array.prototype.delChongfu = function() {//刪除所有重複的元素
i = 0;
while (i<this.length) {
j = i+1;
while (j<this.length) {
if (this[j] == this[i]) {
for (k=j+1; k<this.length; k++) {
this[k-1] = this[k];
}
this.length--;
} else {
j++;
}
}
i++;
}
};
b.delChongfu()
trace(b);
n=getTimer();
Array.prototype.randomize = function() {
this.sort(function(a, b) { return random(2)>0 ? 1 : -1;});
}
var myArray = new Array();
for(var i=0;i<1000;i++){
myArray[i]=i;
}
myArray.randomize();
trace(myArray);
trace(getTimer()-n);
//
Array.prototype.duplicate = function(){
var a = [];
for (var i in this) (this[i] instanceof Array) ? a[i] = this[i].slice() : a[i] = this[i];
return a;
}
var myArray:Array = new Array();
myArray[0]=[1,2]
myArray[1]=3
myArray[2]=[5,6]
var temp:Array = myArray.duplicate();
trace(myArray); //1,2,3,5,6
trace(temp); //1,2,3,5,6
myArray[0][0] = 5;
trace(myArray); //5,2,3,5,6
trace(temp); //1,2,3,5,6