I have a javascript array that contains several objects, each object having this format:
{'hits':21, 'date':2011-01-11, 'business_id':233}
I am using a sorting function to sort the array objects:
my_array.sort(function(a, b){
return b.hits-a.hits;
});
This sorting results in having some adjacent objects with the same 'business_id'. I would like to remove the ones with duplicate 'business_id's to keep only the one of the duplicates having the newest date value.
How do I remove the objects from the array that have duplicate 'business_id', keeping the one with the newest 'date' value? Can I do it in the sort function, or with some filter function?