B
Brion
Is it possible to sort outer and inner strings at once?
The sorted output should look like the following:
<category>Bars</category>
<name>Alpha Bar</name>
<name>Beta Bar</name>
<category>Cafes</category>
<name>Ara Cafe</name>
<name>Zeta Cafe</name>
Categories and names are both properties of one and the same array
element.
I have the following compare function to sort the outer categories.
function compareCats(a, b) {
a = a.category;
b = b.category;
if(a == b) return 0;
else if(a > b) return 1;
else return -1;
}
This is working fine.
But I really would like to include the inner names in the compare
function without changing the structure of the array - if it could be
possible. If not - what would be an efficient way to solve the problem?
The sorted output should look like the following:
<category>Bars</category>
<name>Alpha Bar</name>
<name>Beta Bar</name>
<category>Cafes</category>
<name>Ara Cafe</name>
<name>Zeta Cafe</name>
Categories and names are both properties of one and the same array
element.
I have the following compare function to sort the outer categories.
function compareCats(a, b) {
a = a.category;
b = b.category;
if(a == b) return 0;
else if(a > b) return 1;
else return -1;
}
This is working fine.
But I really would like to include the inner names in the compare
function without changing the structure of the array - if it could be
possible. If not - what would be an efficient way to solve the problem?