A challenging scenario I need help with involves an array containing objects, each with a score and a rank as shown below:
[
{ "score": 20, "rank": 12 },
{ "score": 20, "rank": 7 },
{ "score": 34, "rank": 4 }
]
To begin with, I must organize this array in descending order based on the score and then store it in a 2-dimensional array.
[34, 4]
[20, 12]
[20, 7]
However, the challenge arises when there are multiple objects with the same score. In such cases, I want to further sort them based on their ranks, with the object having the lowest rank having a smaller index number. This should result in the following arrangement:
[34, 4]
[20, 7]
[20, 12]
Despite attempting various methods, I have not been able to find a satisfactory solution to achieve this sorting. Any assistance on this matter would be greatly appreciated.