Search the archives!
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Javascript] Array Numerical Sorting
- From: flavio at economisa.com.br (Flávio Gomes)
- Subject: [Javascript] Array Numerical Sorting
- Date: Thu Nov 30 10:21:12 2006
I was trying to sort an array numerically and couldnt make it untill I found it on this website: http://javascript.about.com/library/blsort.htm Example below: a = new Array(); for (x=0;x<7;x++) { a[x] = Math.ceil ( 12 * Math.random() ); } document.write('<br>'); function numOrdAsc(a, b){ return (a-b); } function numOrdDesc(a, b){ return (b-a); } a.sort( numOrdAsc ); document.write(Ascending : ' + a + '<br>'); a.sort( numOrdDesc ); document.write('Descending : ' + a + '<br>'); Hope it to help someone =) http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Global_Objects:Array:sort <-- best reference found -- Flavio Gomes flavio@xxxxxxxxxxxxxxxx
- Prev by Date: [Javascript] dynamically hide an element
- Next by Date: [Javascript] dynamically hide an element
- Previous by thread: [Javascript] Quick question on passing reference to url
- Index(es):