Arjuna Aircraft Ident.: F-MBSD | t'ain c'est terrible ce truc
Code :
- <script type="text/javascript">
- array1=new Array()
- function myObj(x, y)
- {
- this.valx = x;
- this.valy = y;
- this.toString = function ()
- {
- return "{" + this.valx + ", " + this.valy + "}";
- }
- }
- function compareNum(a,b)
- {
- return a.valx-b.valx;
- }
- var array1 = new Array(new myObj(800, 30), new myObj(3, 40), new myObj(70, 10));
- var array2 = new Array(new myObj(800, 30), new myObj(3, 40), new myObj(70, 10));
- array2.toString = function ()
- {
- var ret = new String();
- for (var i = 0; i < this.length; i++)
- {
- ret += this[i].valx + ", ";
- }
- if (ret.length > 0)
- return ret.substr(0, ret.length - 2);
- else
- return "tableau vide!";
- }
- document.write("Sorted with compareNum: " + array2.sort(compareNum) + "<br/>" );
- document.write("Array1: " + array1 + "<br/>" );
- </script>
|
Message édité par Arjuna le 16-08-2005 à 22:50:42
|