if I have one simple array
1
4
2
6
for to order the code is:
arrayOrdin=arraySimple.sort();
and I have
1
2
4
6
but if array isn't simple:
1,car,blue
4,book,red
2,house,green
6,bicycle,pink
how I can to make the order based only on first column?;
fo to have this
1,car,blue
2,house,green
4,book,red
6,bicycle,pink 4 2003
On 26 Mai, 12:05, artev <mailnotspa...@notspamm.nnwrote:
if I have one simple array
1
4
2
6
for to order the code is:
arrayOrdin=arraySimple.sort();
and I have
1
2
4
6
but if array isn't simple:
1,car,blue
4,book,red
2,house,green
6,bicycle,pink
how I can to make the order based only on first column?;
fo to have this
1,car,blue
2,house,green
4,book,red
6,bicycle,pink
You can call an userdefined function to do the sorting of
multidimentional arrays.
Example:
[snip]
function sortByNumber(a, b){
return a[0] - b[0];
}
function sortByType(a, b){
var a2 = a[1].toLowerCase();
var b2 = b[1].toLowerCase();
return ((a < b) ? -1 : ((a b) ? 1 : 0));
}
function sortByColor(a, b){
var a2 = a[2].toLowerCase();
var b2 = b[2].toLowerCase();
return ((a < b) ? -1 : ((a b) ? 1 : 0));
}
arraySortNum = arraySimple.sort(sortByNumber);
arraySortType = arraySimple.sort(sortByType);
arraySortColor = arraySimple.sort(sortByColor);
[/snap]
purcaholic
why in the simple sort the final order is different respect at
sort of an array?
I use the same role for a list simpleand for a list that is the first
column of an array?
I want for the 1st column of array sort (a-b multiple in the table) how
a-b simpleM where is the error?
here the complete test:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Doc</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">
//
//
function test3()
{
var cont_3a0=document.formbas.cont_3a0 ; var
cont_3a1=document.formbas.cont_3a1 ; var cont_3a2=document.formbas.cont_3a2
;
var cont_3b0=document.formbas.cont_3b0 ; var
cont_3b1=document.formbas.cont_3b1 ; var cont_3b2=document.formbas.cont_3b2
;
var cont_3bb0=document.formbas.cont_3bb0 ; var
cont_3bb1=document.formbas.cont_3bb1 ; var
cont_3bb2=document.formbas.cont_3bb2 ;
var cont_3bbb0=document.formbas.cont_3bbb0 ; var
cont_3bbb1=document.formbas.cont_3bbb1 ; var
cont_3bbb2=document.formbas.cont_3bbb2 ;
var cont_3bbbb0=document.formbas.cont_3bbbb0 ; var
cont_3bbbb1=document.formbas.cont_3bbbb1 ; var
cont_3bbbb2=document.formbas.cont_3bbbb2 ;
//var myarray_base0= new
Array(10,16,35,"0,1",8,4,22,19,1,4,-4,-8,-2,22,35,9,26,38,40);
// var myarray_base0= new
Array(10,8,1,"_casa","__bb",'002','003','004',005, 006,007,".thumb","._thumb",'auto','-parc0','bici','0_auto','BICI','CASA','casa');
var myarray_base0= new
Array(10,8,1,"_house","__bb",'002','003','004',005 ,006,007,".test","._test",'autoveicle','-park','bicycle','0_car','BICYCLE','HOUSE','house') ;
var myarray_base1= new
Array('a','b','c','d','e','f','g','h','i','l','m', 'n','o','p','q','r','s','t','u','v');
var myarray_base2= new
Array('aa','bb','cc','dd','ee','ff','gg','hh','ii' ,'ll','mm','nn','oo','pp','qq','rr','ss','tt','uu' ,'vv'
);
//0
cont_3a0.options.length=0;
var x=0;
for (var i = 0; i<myarray_base0.length; i++)
{ cont_3a0.options[x++]=new Option( myarray_base0[i]); }
//1
cont_3a1.options.length=0;
var x=0;
for (var i = 0; i<myarray_base1.length; i++)
{ cont_3a1.options[x++]=new Option( myarray_base1[i]); }
//2
cont_3a2.options.length=0;
var x=0;
for (var i = 0; i<myarray_base2.length; i++)
{ cont_3a2.options[x++]=new Option( myarray_base2[i]); }
//
================================================== ================================================== ===============
// SORT NORMAL
var order01=new Array();
order01=myarray_base0.sort();
cont_3b0.options.length=0;
var x=0;
for (var i = 0; i<order01.length; i++)
{ cont_3b0.options[x++]=new Option( order01[i]); }
//sort a-b
function sort0(a,b)
{
a - b;
}
var order01bb=new Array();
order01bb=myarray_base0.sort(sort0);
cont_3bb0.options.length=0;
var x=0;
for (var i = 0; i<order01bb.length; i++)
{ cont_3bb0.options[x++]=new Option( order01bb[i]); }
//
================================================== ================================================== ===============
// SORT WITH MULTICOLUMN
function sort2(a,b)
{
a[0] - b[0];
}
var arrayTotale=new Array();
for (var i = 0; i <myarray_base0.length; i++)
{
arrayTotale[i]=new Array();
arrayTotale[i][0]=myarray_base0[i];
arrayTotale[i][1]=myarray_base1[i];
arrayTotale[i][2]=myarray_base2[i];
}
var order01bb=new Array();
order01bb=arrayTotale.sort(sort2);
cont_3bb0.options.length=0;
cont_3bb1.options.length=0;
cont_3bb2.options.length=0;
var x=0;
for (var i = 0; i<arrayTotale.length; i++)
{ cont_3bb0.options[x++]=new Option( order01bb[i][0]);
cont_3bb1.options[x++]=new Option( order01bb[i][1]);
cont_3bb2.options[x++]=new Option( order01bb[i][2]);
}
}
</script>
</head>
<BODY>
<form name="formbas" action="" method="post">
<!-- -->
<!-- -->
<table border="1">
<tr>
<td>List </td><td></td><td></td>
<td>a-b simple </td>
<td></td><td></td>
<td>a-b multipl </td>
<td></td><td></td>
</tr>
<tr>
<td><select name="cont_3a0" size="22" style="width:100px" ></select></td>
<td><select name="cont_3a1" size="22" style="width:50px" ></select></td>
<td><select name="cont_3a2" size="22" style="width:50px" ></select></td>
<td><select name="cont_3b0" size="22" style="width:100px" ></select></td>
<td><select name="cont_3b1" size="22" style="width:50px" ></select></td>
<td><select name="cont_3b2" size="22" style="width:50px" ></select></td>
<td><select name="cont_3bb0" size="22" style="width:100px" ></select></td>
<td><select name="cont_3bb1" size="22" style="width:50px" ></select></td>
<td><select name="cont_3bb2" size="22" style="width:50px" ></select></td>
</tr>
</table>
<br>
<input type="button" name="puls" value="TEST3" onClick="test3()"
/><br><br><br>
<br><br>
<!-- -->
<!-- -->
<br><br>
</form>
</BODY>
</html>
artev said:
> why in the simple sort the final order is different respect at sort of an array? I use the same role for a list simpleand for a list that is the first column of an array? I want for the 1st column of array sort (a-b multiple in the table) how a-b simpleM where is the error?
This function does nothing:
function sort2(a,b)
{
a[0] - b[0];
}
I'll bet you meant:
function sort2(a,b)
{
return a[0] - b[0];
}
You also need to work more on choosing the correct English prepositions.
I imagine that's fairly difficult to learn.
--
function sortByColor(a, b){
var a2 = a[2].toLowerCase();
var b2 = b[2].toLowerCase();
return ((a < b) ? -1 : ((a b) ? 1 : 0));
}
you use var a2 and var b2 but after in the expression they aren't used
in my simple test if I use:
function sort2(a,b){
a=a.toLowerCase();
b=b.toLowerCase();
if (a<b) return -1;
if (a>b) return 1;
return 0;
}
I have with consol javascript an error:
toLOwerCAse isn't a function This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Kamilche |
last post by:
I've written a generic sort routine that will sort dictionaries,
lists, or tuples, either by a specified key or by value.
Comments welcome!
import types
def sort(container, key = None,...
|
by: its me |
last post by:
Let's say I have a class of people...
Public Class People
Public Sex as String
Public Age as int
Public Name as string
end class
And I declare an array of this class...
|
by: Elijah Bailey |
last post by:
I want to sort a set of records using STL's sort() function,
but dont see an easy way to do it.
I have a
char *data;
which has size mn bytes where m is size of the record and
n is the...
|
by: Stuart |
last post by:
The stl::sort() that comes with Dev Studio 6 is broken (it hits the
degenerate case in a common situation). I have a replacement.
I would like to globally do "using namespace std; except use my...
|
by: DC Gringo |
last post by:
I have a datagrid that won't sort. The event handler is firing and return
label text, just not the sort.
Here's my Sub Page_Load and Sub DataGrid1_SortCommand:
--------------------
Private...
|
by: Alex Chudnovsky |
last post by:
I have come across with what appears to be a significant performance bug in
..NET 2.0 ArrayList.Sort method when compared with Array.Sort on the same
data. Same data on the same CPU gets sorted a...
|
by: Woody Ling |
last post by:
In 32 bits DB2 environment, is it meaningful to set sheapthres larger
than 256MB for the following case..
1. Intra-parallel is ON
2. Intra-parallel is OFF
|
by: artev |
last post by:
in the default sort which is the compare function used?
alphabetical ordination is so:arry.sort();
but which is the default function used?
is there a good link wich example for alphabetical...
|
by: neehakale |
last post by:
I know that heap sort,quick sort and merg sort are the faster sorting algoritms than the bubble sort,selection sort,shell sort and selection sort.
I got an idea,in which situation we can use...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |