Outer array should be sorted based on the combination of rankings of each student's variable-length inner "tests" array, ascending. Here's a simplified version of the raw data.
[
{
"studentId": "A",
"tests": [
{
"testId": 100,
"rank": 2
},
{
"testId": 101,
"rank": 1
},
{
"testId": 102,
"rank": 1
}
]
},
{
"studentId": "G",
"tests": [
{
"testId": 103,
"rank": 3
},
{
"testId": 104,
"rank": 6
},
{
"testId": 105,
"rank": 3
},
{
"testId": 106,
"rank": 4
},
{
"testId": 107,
"rank": 3
}
]
}
]
For brevity, here is an illustration commented to capture the rules for sorting and tie-breaking. Imagine each of the below represents the pre-sorted sequence of each student's individual test ranks. (Note that testIds don't matter, other than to preserve them. We're not concerned with comparing individual tests, only each student's overall combination of ranks):
StudentId : [ascending sequence of test ranks]
A : [ 1, 1, 2] // A beats B due to 2nd element
B : [ 1, 2, 2] // B beats C due to 1st element
C : [ 2, 3] // Let C beat D due to shorter length!
D : [ 2, 3, 3] // D beats E due to 1st element
E : [ 3, 3, 3, 4, 5, 7] // E beats F and G due to 5th element
F : [ 3, 3, 3, 4, 6] // F and G are tied. Let F beat G due to studentId! (alphanumeric ascending)
G : [ 3, 3, 3, 4, 6]
None of the raw data is sorted. Finished output to include sorted outer array, with each student's test array sorted by rank. Please let me know if anything's unclear, and thank you.