var company=new Array("Kestrel Moon","BB")
var femalePri=new Array(89,0)
for(var i=0;i<2;i++){
var companyTotal=company[i].concat(finalTotal[i]);
document.write(""+companyTotal+"");
this displays:
Kestrel Moon 89
BB 0
I want it so that it displays in ascending order of number
BB 0
Kestrel Moon 89
The problem is that when I do a normal sort array, it puts the company names in alphabetical order and the price stays as it is and if I sort the numbers in ascending order, the numbers go in ascending order but the company names stays where ther are.
I want it so that numerically its in acscending order and when the price is placed in ascending order, their company names go with their prices, can this be done and if it can, can you please show me an example?
<SCRIPT type="text/javascript">
//Concat the 2 arrays with the number going first, name second. Then, sort by parseInt()
var company=new Array("Kestrel Moon","BB")
var femalePri=new Array(89,0)
var companyTotal=[]
for(i=0;i<2;i++){ companyTotal[i]=femalePri[i]+'~'+company[i];}
companyTotal.sort(function(a,b){return parseInt(a) - parseInt(b)});
document.write( companyTotal.join('<br>') );
document.write( '<P>' );
//each element of companyTotal can now be split into an Array in
// order to write it with name first
for(i=0;i<companyTotal.length;i++){companyTotal[i]=companyTotal[i].split('~');
document.write(companyTotal[i][1]+' '+companyTotal[i][0]+'<br>')}
</SCRIPT>
Using 'justinbarneskin's sort function and my idea of combining the master array,
you could do something like this (or modify further for the remaining fields) ...
Bookmarks