[ascoders] Re: mix function sort()
- From: Michael Kneib <listen@xxxxxxxxx>
- To: ascoders@xxxxxxxxxxxxx
- Date: Tue, 06 May 2003 11:14:45 +0200
Andre Michelle wrote:
wo gibt es mehr Informationen zur
manuellen Sor(tier)funktion für Array.sort();
Damit ich verstehe, warum das NICHT mein
Array zufällig "sortiert".
var mix = function ( a , b ) {
return ( Math.random() < .5 ) ? a : b;
}
var arr = [ 1 , 2 , 3 , 4 , 5 , 6 ];
arr.sort( mix );
Bei Array.sortOn kann man keine Sortierfunktion übergeben, oder doch -
anders ?
ich verstehe nicht warum du a oder b zurückgeben willst.
als rückgabe der sort-funktion wird doch 0, 1 oder -1 erwartet,
a und b sind aber arrayinhalte:
var mix = function ( a , b ) {
trace(a);
trace(b);
return ( Math.random() < .5 ) ? a : b;
}
warum nicht bokels klassiker?
var mixen = function () {
return random(3)-1;
};
gruß
michael
------------------------------------------------------
Archiv : http://www.freelists.org/archives/ascoders/
Optionen : http://www.freelists.org/list/ascoders
------------------------------------------------------
- Follow-Ups:
- [ascoders] Re: mix function sort()
- From: Andre Michelle
- References:
- [ascoders] mix function sort()
- From: Andre Michelle
Other related posts:
- » [ascoders] mix function sort()
- » [ascoders] Re: mix function sort()
- » [ascoders] Re: mix function sort()
- » [ascoders] Re: mix function sort()
- » [ascoders] Re: mix function sort()
wo gibt es mehr Informationen zur manuellen Sor(tier)funktion für Array.sort();
Damit ich verstehe, warum das NICHT mein Array zufällig "sortiert".
var mix = function ( a , b ) {
return ( Math.random() < .5 ) ? a : b;
}var arr = [ 1 , 2 , 3 , 4 , 5 , 6 ]; arr.sort( mix );
Bei Array.sortOn kann man keine Sortierfunktion übergeben, oder doch - anders ?
gruß michael
- [ascoders] Re: mix function sort()
- From: Andre Michelle
- [ascoders] mix function sort()
- From: Andre Michelle