Change sorting logic in analysis function.

JavaScript array sort() function doesn't work well.