javascript - A reliable way of sorting an array and passing that information to a view -
i using expressjs render routes , pass on database information.
for(var i=0; i<paintingjobs.length; i++) { for(j=0; j<customerlist.length; j++) { if (customerlist[j].id == paintingjobs[i].customerid) { customerrecords.push(customerlist[j]); } } } creating new filtered array of customerrecords, passed view.
question is: if sort (1)paintingjobs array date prior using filter (1)customerlist, resulting array (customerrecords) sorted date or more reliable method? if not, appending date customerlist , sorting final array next best solution?
i passing information view , creating unordered list based on number of records.
thank time , suggestions
your double-loop preserves order of paintingjobs in customerrecords, though unless have duplicate customerlist id's, looks inefficient (why no break?).
means changes order of paintingjobs before double loop reflected in customerrecords. changes after not.
paintingjobs.sort(however); for(var i=0; i<paintingjobs.length; i++) { for(j=0; j<customerlist.length; j++) { if (customerlist[j].id == paintingjobs[i].customerid) { customerrecords.push(customerlist[j]); break; // next paintingjob } } } it looks items in customerlist objects, if make change object in customerlist, change appear in customerrecords after double loop.
Comments
Post a Comment