I am attempting to alphabetize an array in TypeScript without regard to case sensitivity. In JavaScript, this could be achieved with
list.sort(function (a, b) {
return a.toLowerCase().localeCompare(b.toLowerCase());
});
In TypeScript, the sorting logic resembles
list.sort((a, b) => {
if (a > b) {
return 1;
}
if (a < b) {
return -1;
}
return 0;
});
Given [F, E, D, c, b, a] as input, I anticipate receiving [a, b, c, D, E, F]
The JavaScript sort method produces the anticipated outcome, but the TypeScript sort results in [D, E, F, a, b, c]. How can I enforce case insensitivity in the TypeScript sorting process?
EDIT: The reason I cannot employ the JavaScript technique is due to the fact that in TypeScript, variables a and b are of boolean type and do not possess the toLowerCase() method.