I'd like to sort a two dimensional array using javascript.
My array :
[
['1','6'],
['1','5'],
['2','3'],
['0','4'],
]
My sorting function :
// 1st sort
myArray.sort( function(a, b) {
return a[0] - b[0];
});
// 2nd sort
myArray.sort( function(a, b) {
return a[1] - b[1];
});
The result :
["2", "3"]
["0", "4"]
["1", "6"]
["1", "5"]
The result should be :
["0", "4"]
["1", "5"] // 5 before 6 and the left column is sorted
["1", "6"]
["2", "3"]