BC468Part VIBonus Chapterscase byQ2Quota : (Web hosting account) db.sort(sortDBByQ2Quota); break; case
BC468Part VIBonus Chapterscase byQ2Quota : db.sort(sortDBByQ2Quota); break; case byQ3Fcst : db.sort(sortDBByQ3Fcst); break; case byQ3Actual : db.sort(sortDBByQ3Actual); break; case byQ3Quota : db.sort(sortDBByQ3Quota); break; case byQ4Fcst : db.sort(sortDBByQ4Fcst); break; case byQ4Actual : db.sort(sortDBByQ4Actual); break; case byQ4Quota : db.sort(sortDBByQ4Quota); break; case byTotalFcst : db.sort(sortDBByTotalFcst); break; case byTotalActual : db.sort(sortDBByTotalActual); break; case byTotalQuota : db.sort(sortDBByTotalQuota); break; } drawTextTable(); } Each specific sorting routine is a function that automatically works repeatedly on pairs ofentries of an array (see Chapter 30). Array entries here (from the dbarray) are objects andrather complex objects at that. The benefit of using JavaScript array sorting is that the sort- ing can be performed on any property of objects stored in the array. For example, sorting onthe lastNameproperty of each dbarray object is based on a comparison of the lastNameproperty for each of the pairs of array entries passed to the sortDBByRep()sort function. But looking down a little further, you can see that the mechanism allows sorting on evenmore deeply nested properties, such as the sales.Q1_2000.forecastproperty of eacharray entry. If a property in an object can be referenced, it can be used as a sorting propertyinside one of these functions. function sortDBByRep(a, b) { if (document.getElementById( orderChooser ).value == inc ) { return (a.lastName < b.lastName) ? -1 : 1; } else { return (a.lastName > b.lastName) ? -1 : 1; } } function sortDBByRegion(a, b) { if (document.getElementById( orderChooser ).value == inc ) { return (a.region < b.region) ? -1 : 1; } else { return (a.region > b.region) ? -1 : 1; } }