I am looking to sort an array in two ways....
First: Sort by an integer field and then by text field - example sort but total count value and then by a animal name
Second: Sort by a text field and then another text field - example sort by an animal species, and then by its common name
Any thoughts?
Below I can sort by either Integer or Text but not both.
var sort_by = function(field, reverse, primer){
var key = primer ?
function(x) {return primer(x[field])} :
function(x) {return x[field]};
reverse = !reverse ? 1 : -1;
return function (a, b) {
return a = key(a), b = key(b), reverse * ((a > b) - (b > a));
}
}
//SORT TEXT FIELD
//newarr.sort(sort_by('GENUSalse, function(a){return a.toUpperCase()}));
// SORT INTERGER FIELD
newarr.sort(sort_by('ObsIDalse, function(a){return a}));
First: Sort by an integer field and then by text field - example sort but total count value and then by a animal name
Second: Sort by a text field and then another text field - example sort by an animal species, and then by its common name
Any thoughts?
Below I can sort by either Integer or Text but not both.
var sort_by = function(field, reverse, primer){
var key = primer ?
function(x) {return primer(x[field])} :
function(x) {return x[field]};
reverse = !reverse ? 1 : -1;
return function (a, b) {
return a = key(a), b = key(b), reverse * ((a > b) - (b > a));
}
}
//SORT TEXT FIELD
//newarr.sort(sort_by('GENUSalse, function(a){return a.toUpperCase()}));
// SORT INTERGER FIELD
newarr.sort(sort_by('ObsIDalse, function(a){return a}));