sort array

Joined
Oct 18, 2015
Messages
5
Reaction score
0
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}));
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,813
Latest member
lawrwtwinkle111

Latest Threads

Top