Click to See Complete Forum and Search --> : sorting part 2


z_mirza
06-06-2003, 07:26 PM
ok heres another problem im having, i have a table of tag names, in the next row is a small one line desc of the tag, well i need to put the tag names in to an array, and sort them using the sort Dave Clark gave me, (see Sorting arrays) and still have the desc go to the right tag name, let me start you guys off


arrParts = arrData[idx].split("|");
// splited some data into 3 different parts the parts are below
v1 = arrParts[0];
v2 = arrParts[1];
v3 = arrParts[2];

aLink = document.createElement("a");
aLink.innerText = v1;
aLink.href = v2;
aLink.id = "Element";
aLink.className = "element";
description = v3;

return aLink;

v1 is the tag name, v2 is a link to another page, v3 is the desc

the number of arrParts[0] is determeined by how many tagnames there are in the table, i have it set up dynaicmly, so how would i sort all of the v1's that come out of this function (by the way arrParts[0] changes X number of times, x being the number of tagnames i have in the table) and keep the right v3 with it. thanx alot if you need to see more of my code let me know or if you need further explantion as to what im saying let me know because i can see how this could get confusing. thanx again guys

z_mirza
06-06-2003, 10:24 PM
using the .sort wont mess up the corresponding desc?

z_mirza
06-06-2003, 10:31 PM
and could you please explain you code a bit more, because i didnt do it right, or it didnt work

arrParts = arrData[idx].split("|");
var sortParts = new Array;
sortParts = arrParts.sort();
v1 = sortParts[0];
v2 = sortParts[1];
v3 = sortParts[2];

i didnt get the desired output

z_mirza
06-07-2003, 09:58 AM
can you tell me why this doesnt sort?


arrParts = arrData[idx].split("|");
for(i = 0; i < arrParts.length; i += 3)
for(j=0; j < arrParts.length; j += 3)
if(arrParts[i].toLowerCase() < arrParts[j].toLowerCase())
{
var temp = arrParts[i], temp1 = arrParts[i+1], temp2 = arrParts[i+2];
arrParts[i] = arrParts[j];
arrParts[i+1] = arrParts[j+1];
arrParts[i+2] = arrParts[j+2];
arrParts[j] = temp;
arrParts[j+1] = temp1;
arrParts[j+2] = temp2;
}
v1 = arrParts[0];
v2 = arrParts[1];
v3 = arrParts[2];

z_mirza
06-07-2003, 12:04 PM
got it working, thanx for showing me the sorts, dave, couldnt have done it without u

arrData = sData.split("*");
for(i = 0; i < arrData.length; i++)
for(j = 1; j < arrData.length; j++)
if(arrData[i] < arrData[j])
{
var temp = arrData[i];
arrData[i] = arrData[j];
arrData[j] = temp;
}
arrParts = arrData[idx].split("|");
v1 = arrParts[0];
v2 = arrParts[1];
v3 = arrParts[2];