Fixed an issue which resulted in wrong sorting of the activity list

I found a minor issue regarding sorting of questions. See image below:

![screen shot 2014-07-14 at 10 35 40](https://cloud.githubusercontent.com/assets/1449790/3576101/2027155a-0b8f-11e4-84b9-2396ec78e16e.png)

It's pretty clear @Scott was out for a while and came back just to brake things :)

This should be the case to replicate the issue:

1. Post question Q1
1. Post question Q2
1. Post comment C1 to Q1
1. Post comment C2 to Q2
1. Edit C1 ~1.5 minutes after its creation (before the 5 minute grace period runs out and after 1 minute has passed since its creation)

Expected sort order in the activity list (top to bottom): Q2 and then Q1
Actual sort order: Q1 and then Q2

Actually, the sort order is at first sight broken. If the page is refreshed for several seconds Q1 will be eventually be displayed as older than Q2. EG: Q1 will display "commented 2 minutes ago" and Q2 will display "commented 1 minute ago".

This seems to be happening because the core sorts based on one date: either the creation date or the update date of a child post. Now, the activity list filters taking into account update dates as the idea is that if a comment gets edited it gets that question up to the first position of the activity list. So it makes sense for the upper question to be Q2. However, I guess the requirement is it should sort based on the creation date if the post has no edits or the edit has been performed in the initial 5 minutes. So there is a bug there.

I guess the issue is located here: https://github.com/q2a/question2answer/blob/dev/qa-include/qa-app-format.php#L917 . In short, there are a bunch of posts taken from the database and happen to be "duplicated". That means, for example, having more than one Q1 as an item in the array, as the array contains the question, the comment and its edition. Then the function chooses one of them and gets rid of the rest. This process works perfectly fine. Only issue is if the first one it finds is not the one it should keep it gets replaced by an older post but the array keeps the original position. So the solution I'm proposing is getting rid of that originally added one and add the new one in the newly updated position. I know this sounds like a riddle but if you take a look at the function in detail you'll get what I mean.

So first commit should fix the issue in a git-friendly way. Second commit is a small refactor of the function.

PS: This could be added to a 1.6.4 release, if needed