I have a function that sorts an array and within it, I have custom sort functions. Something like this:
function SortTheArray() {
function SortCriteria1Asc(a, b) { ... }
function SortCriteria1Dsc(a, b) { ... }
function SortCriteria2Asc(a, b) { ... }
function SortCriteria1Asc(a, b) { ... }
var CustomSort;
switch (SomeVar) {
case 1:
CustomSort = SortCriteria1Asc;
break;
case 2:
CustomSort = SortCriteria1Dsc;
break;
case ....
}
SomeDataArray.sort(CustomSort);
}
Is it possible to remove the switch statement and say that the CustomSort function is simply equal to the nth nested function?
Thanks for your suggestions.