Prototype: Array.shuffle [Flash 8]
| 01.07.2003, 23:34 | | Beiträge: 6940 Wohnort: München Registriert: Jan 2002
| Prototype: Array.shuffle Array in zufälliger Reihenfolge sortieren
Prototype:
ActionScript:1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | // ## Ohne Typ Umwandlung: ############################
function rand() {
return random(3)-1;
}
Array.prototype.shuffle = function() {
return this.sort(rand);
}
ASSetPropFlags(Array.prototype,"shuffle",1,true);
// ## Typ Umwandlung: ############################
Array.prototype.shuffle = function() {
var temp_ary = [];
while(this.length) temp_ary.push(this.splice(random(this.length),1));
return temp_ary;
}
ASSetPropFlags(Array.prototype,"shuffle",1,true);
|
Beispiel Aufruf:
ActionScript:1 2 3 | test_ary = ["eins","zwei","drei","vier","fünf"];
neues_ary = test_ary.shuffle();
trace(neues_ary)
|
Flex Freelancer || Flashhilfe @ Twitter || XING Profil | |
| | Themen Ähnliche Beiträge zum Thema | 15.07.2009 - fevzi 15.10.2009 - coarsy 16.06.2010 - skoda 15.09.2010 - ole4 |
|
Flashhilfe.de Flash Platform Tipps & Tutorials Flash Platform Andere Programmiersprachen Jobangebote Diskussionen
Flashhilfe News 
Regeln & Bedingungen
|