1

How can I sort this dataset by its value [1] (4,10,19) so it returns as A,C,B?

var dataset = [
        ["A","4","570"],
        ["B","19","123"],
        ["C","10","395"],
    ];

Test: http://jsfiddle.net/2js5x/

explunit
  • 18,967
  • 6
  • 69
  • 94
Martin
  • 2,007
  • 6
  • 28
  • 44

1 Answers1

1

Here you are sir http://jsfiddle.net/2js5x/1/ just using custom sort :)

function on_first(a,b){
    return a[1]-b[1]; 
}

You may evolve the custom sort to do the sum, else...

nicolallias
  • 1,055
  • 2
  • 22
  • 51