I'm trying to sorted my array
. I'm trying to sort the blocks by the [2]
entry in each of the square brackets. So the 15th should be at the top and the 8th should be second and so on.
I've tried using.
var sorted = data.sort(function(a,b){return b[2]-a[2]});
console.log(sorted);
and
data.sort(function(a,b){return b[2]-a[2]});
console.log(sorted);
but this didn't work. Is it because the numbers are stored as text? if so i've tried par
data.sort(function(a,b){return parseFloat(b[2])-parseFloat(a[2])});
console.log(sorted);
and this didn't work either.
0:(2) ["HDR", "GENERATION BY FUEL TYPE CURRENT Last Updated At 20180719150500"]
1:(2) ["FTR", "14"]
2:(8) ["FUELINSTHHCUR", "OCGT", "0", "0.0", "0", "0.0", "0", "0.0"]
3:(8) ["FUELINSTHHCUR", "OIL", "0", "0.0", "0", "0.0", "0", "0.0"]
4:(8) ["FUELINSTHHCUR", "COAL", "947", "3.0", "900", "2.9", "15144", "2.2"]
5:(8) ["FUELINSTHHCUR", "NUCLEAR", "6407", "20.4", "6477", "20.8", "158268", "22.5"]
6:(8) ["FUELINSTHHCUR", "WIND", "1710", "5.4", "1678", "5.4", "11903", "1.7"]
7:(8) ["FUELINSTHHCUR", "PS", "165", "0.5", "174", "0.6", "6854", "1.0"]
8:(8) ["FUELINSTHHCUR", "CCGT", "17355", "55.2", "17144", "55.1", "382043", "54.3"]
9:(8) ["FUELINSTHHCUR", "OTHER", "59", "0.2", "59", "0.2", "1406", "0.2"]
10:(8) ["FUELINSTHHCUR", "INTFR", "1998", "6.4", "1998", "6.4", "47363", "6.7"]
11:(8) ["FUELINSTHHCUR", "INTIRL", "0", "0.0", "0", "0.0", "1960", "0.3"]
12:(8) ["FUELINSTHHCUR", "INTNED", "1001", "3.2", "1000", "3.2", "23097", "3.3"]
13:(8) ["FUELINSTHHCUR", "INTEW", "0", "0.0", "0", "0.0", "4803", "0.7"]
14:(8) ["FUELINSTHHCUR", "BIOMASS", "1649", "5.2", "1621", "5.2", "48031", "6.8"]
15:(7) ["TOTAL", "31448", "100.0", "31128", "100.0", "703547", "100.0"]
16:(8) ["FUELINSTHHCUR", "NPSHYD", "157", "0.5", "77", "0.2", "2675", "0.4"]
any help would be appreciated.