Return a compare function to sort objects by a given property