I’ve always been an advocate of the DRY principle: in other words, write code once and only once. I have a function that essentially filters out data by “latest unique report”. In my algorithm, the function assumes the incoming data is sorted, making it very efficient. However, this function potentially has to handle data that is not sorted. What is the better practice: having one general solution that will be slower, or having two slightly different functions, with one being much more efficient?
EDIT: I should make note that while performance is a nice thing to have, it is not critical for the application as it is an internal tool.
The way you put it it sounds like you could just make a function that sorts the data, and then puts it into the filtering function.
So