When sorting upgrades with a point cost of multiple digits, it appears that they are sorted according to the first digit. Luke (30 points) is placed between 4 and 2-point gunners, and all the 10+ point crew is placed after the cheapest.
Bug: Upgrades sorted by cost don't work propperly
Wow, classic sorting bug when doing quick n dirty programming.
Lexicographic sorting works by comparing character vs character so 10 comes before 2 because 1 is lower than 2. This can be handled either by ensuring all numbers are equal length before you call a Sort() (e.g. changing 1 to 01 if you want to compare it with 10-99) and/or or you can create a custom comparator that first compares # of characters ie single digit or double digit.
Or just compare them as if they are numbers and not text? They are numerical costs after all.
The problem here is that they are sorting numbers alphabetically as if they were words, not numerically.
On 9/27/2018 at 7:03 AM, westiebestie said:Wow, classic sorting bug when doing quick n dirty programming.
Lexicographic sorting works by comparing character vs character so 10 comes before 2 because 1 is lower than 2. This can be handled either by ensuring all numbers are equal length before you call a Sort() (e.g. changing 1 to 01 if you want to compare it with 10-99) and/or or you can create a custom comparator that first compares # of characters ie single digit or double digit.
Or just convert the strings to int's