I'm trying to get three columns sorted in an array in Google Apps Script. I realize there are lots of explanations, but I'm not getting it. I was hoping someone could troubleshoot the code snipper below.
Desired functionality: sort an array using 'columns' 8,9,10 (text and nulls), in order.
Issue: nulls don't seem to get sorted properly.
Code snippet:
shdv.sort(function(a,b){
var so = -1
a[10]>b[10] ? so=1 : null; // section
a[10] == b[10] && (a[9]>b[9] || a[9] == '') ? so=1 : null;
a[10] == b[10] && a[9]==b[9] && a[8]>a[9] ? so=1 : null;
null;
})
Example result
[Not Tracking, Site, 2.85208117E8]
[Not Tracking, , 2.83812926E8]
[Not Tracking, , 2.83991529E8]
[Not Tracking, Site, 2.83812602E8]
Desired result
[Not Tracking, Site, 2.85208117E8]
[Not Tracking, Site, 2.83812602E8]
[Not Tracking, , 2.83812926E8]
[Not Tracking, , 2.83991529E8]

shdvrange.sort([{column:8,ascending:true},{column:9,ascending:true},{column:10,ascending:true}])Example here