|
Array.moveItem
myArray = new Array("A", "B", "C", "D"); Array.prototype.moveItem = function(item) { var tmp = new Array(); for (j=0; j<this.length; j++) { if (this[j] !=item) { tmp.push(this[j]); } } tmp.push(item); display(tmp); }; myArray.moveItem("C"); function display(c) { trace(c.toString()); } Posted by: Aenema | website http://aenema.altervista.org |
Array.prototype.next=function (currentValue){
var setKey;
for (at in this) {
if (currentValue == this[at]){
return this[setKey];
}
setKey=at;
}
}
Array.prototype.prev=function (currentValue){
var setKey;
var i=0;
for (at in this) {
if (setKey==i){
return this[at];
}
if (currentValue == this[at]){
setKey=(i+1);
}
i++;
}
}
ASSetPropFlags(Array.prototype,["next","prev"],1);
/* example
flashzone=new Array();
flashzone[1]="1-1-1";
flashzone[3]="3-3-3";
flashzone['kk']="kkvalue";
flashzone[7]="7-7-7";
flashzone[25]="25-25-25";
flashzone['zz']="zzValue";
flashzone[11]="11-11-11";
flashzone[13]="13-13-13";
trace("nextValue=> " add flashzone.next("kkvalue"))
trace("================")
trace("prevValue=> " add flashzone.prev("11-11-11"))
*/
Posted by: Mariusz Mielnik | website http://www.flashzone.pl |
// Arrayelemnts to Variables Array.prototype.arrayToVar = function(varname) { if (varname == undefined) varname = "variable"; for (var i = 0; i < personen.length; i++) { _root[varname+"_"+i] = personen[i]; } }; ASSetPropFlags(Array.prototype,"arrayToVar",1,true); personen = ["Matthias","Caroline","Martin","Ralf"]; personen.arrayToVar("person"); // Try for (i in _root) { // trace(i + "=" + _root[i]); ausgabe_txt.text += i+"="+_root[i]+"\n"; } Posted by: Matthias Kannengiesser | website http://www.flashstar.de |
Array.prototype.qsort = function( obj ){
var type = [];
if ( ( typeof obj == "object" ) && ( obj.length == undefined ) ) type.push( obj );
else type = obj;
this.qs( 0 , this.length - 1 , type[ 0 ].prop );
if ( type[ 0 ].order == -1 ) this.reverse();
if ( type.length > 1 ){
for ( var i = 1 ; i < type.length ; i++ ){
var ret = [];
var aux = [];
while ( this.length > 0 ){
aux.push( this.shift() );
if ( this[ 0 ][ type[ i - 1 ].prop ] != aux[ 0 ][ type[ i - 1 ].prop ] ){
ret.push( aux );
aux = [];
}
}
for ( var j = 0 ; j < ret.length ; j++ ){
var a = ret[ j ]
if ( a.length > 1 ) a.qs( 0 , a.length - 1 , type[ i ].prop );
if ( type[ i ].order == -1 ) a.reverse();
for ( var k = 0 ; k < a.length ; k++ ){
this.push( a[ k ] );
}
}
}
}
}
Array.prototype.qs = function( left , right , prop ){
var nInt = function( value ){
return( int( value ) == value ? value : int( value ) + 1 );
}
var i = left;
var j = right;
var x = this[ nInt( ( i + j ) / 2 ) ];
do {
if ( prop == undefined ){
while ( ( this[ i ] < x ) && ( i < right ) ) i++;
while ( ( this[ j ] > x ) && ( j > left ) ) j--;
} else {
while ( ( this[ i ][ prop ] < x[ prop ] ) && ( i < right ) ) i++;
while ( ( this[ j ][ prop ] > x[ prop ] ) && ( j > left ) ) j--;
}
if ( i <= j ){
var aux = this[ i ];
this[ i ] = this[ j ];
this[ j ] = aux;
i++; j--;
}
} while( i <= j );
if ( left < j ) this.qs( left , j , prop );
if ( right > i ) this.qs( i , right , prop );
}
ASSetPropFlags( Array.prototype , [ "qs" , "qsort" ] , 7 , true );
var num = [ 10 , 16 , 33 , 1 , 15 , 21 ];
var str = [ "Joao" , "Jonas" , "Navy" , "Joao" , "Joao" , "Neto" ];
var obj = [ { nome : "Joao" , idade : 10 , local : "ap" },
{ nome : "Jonas" , idade : 16 , local : "rj" },
{ nome : "Navy" , idade : 33 , local : "sc" },
{ nome : "Joao" , idade : 1 , local : "cp" },
{ nome : "Joao" , idade : 15 , local : "bp" },
{ nome : "Neto" , idade : 21 , local : "rs" } ];
num.qsort();
str.qsort();
obj.qsort( [ { prop : "nome" , order : 1 } , { prop : "idade" , order : -1 } ] );
trace( num );
trace( str );
for ( var i = 0 ; i < obj.length ; i++ ){
var p = "";
for ( var j in obj[ i ] )
p += j + ": " + obj[ i ][ j ] + " , ";
trace( p );
}
Posted by: Joćo Neto | website http://www.mugb.com.br |
Array.prototype.randomize = function () {
return this.sort(function(a,b) {return (Math.floor(Math.random()*2) == 0) ? 1 : -1;});
};
myArray = [1,2,3,4,5,6,7,8,9,10];
trace(myArray.randomize());
Posted by: Bryan Ledford | website http://www.cogmatrix.com/bryan |

