I have the following problem:
I try to sort a list of people containing the flag that identifies the person (student or Teacher), the person's code, the person's name, the person's status (active, inactive, blocked) and the status of participation in that room (active, inactive, and locked), all this information inside a vector that I call arrayVelhoAux
. In this I want to sort this vector alphabetically (A, B, C, D, E, ...).
arrayVelhoAux.FLG_IDENT_PESSO = arrayCursor[j].FLG_IDENT_PESSO;
arrayVelhoAux.COD_IDENT_PESSO = pessoa.COD_IDENT_PESSO;
arrayVelhoAux.TXT_NOMEX_PESSO = pessoa.TXT_NOMEX_PESSO;
arrayVelhoAux.FLG_STATU_PESSO = pessoa.FLG_STATU_PESSO;
arrayVelhoAux.FLG_STATU_PARTC = arrayCursor[j].FLG_STATU_PARTC;
arrayVelho.push(arrayVelhoAux);
To fill this vector I am looping because there are data I get in other tables. After the total completion of this vector I make a .sort()
in order to sort it.
arrayVelho.sort(compareArray);
In compareArray
, I simply compare which one is larger. Put all uppercase letters so that they are all compared in the same size.
function compareArray(a1,b1) {
if(a1.TXT_NOMEX_PESSO.toUpperCase() > b1.TXT_NOMEX_PESSO.toUpperCase()) return 1;
if(a1.TXT_NOMEX_PESSO.toUpperCase() < b1.TXT_NOMEX_PESSO.toUpperCase()) return -1;
return 0;
}
Apparently there is nothing wrong, and something interesting happens because you are only comparing some, others are out of order. As in the image below.
I would like to know if there is a better solution than it is, or if you would like to arrange and leave this solution 100% functional.