I am trying to sort my columns based on 'Value' field which is combination of strings and numerical values in the following order
var ascending = ["","","", 0, 0, 0.71, 1]
var descending = [1, 0.71,0,0,"","",""]
I tried the below sorting algorithm, but it is not giving desired results
function mySort(v1,v2) {
var v1 = obj1[colName];
var v2 = obj2[colName];
if(v1 === ""){
return 1;
}
else if(v2 === ""){
return -1;
}
else if(v1 === v2){
return 0;
}
else if(!sortObj.descending) {
return v1 < v2 ? -1 : 1;
}
else if(sortObj.descending) {
return v1 < v2 ? 1 : -1;
}
}
Above sorting algorithm always keeps the "" at bottom, which is not desired in my case. What I am missing?
0)? Because["", "", 0, "", 1, 0.71, 0].map(Number).sort()works fine""comparisons dependant on thesortObj.descending, as inreturn sortObj.descending ? 1 : -1, and the opposite for the second"".