I have an array called criticalityTypes that contains three different levels of criticality: 'CRITICALITY_LOW', 'CRITICALITY_HIGH', and 'CRITICALITY_MEDIUM'.
Currently, the order of these criticality types is random, which means sometimes 'CRITICALITY_LOW' is in position 1, and other times it's at position 2 or 'CRITICALITY_MEDIUM' at position 0.
What I want to achieve is to sort these criticality types in a specific order regardless of how they are randomly arranged. The desired order is: ['CRITICALITY_HIGH', 'CRITICALITY_MEDIUM', 'CRITICALITY_LOW'].
I've attempted to use a sorting function like this:
return criticalityTypes.sort((a, b) => {
if (a < b) return -1;
if (a > b) return 1;
});
However, my current approach has not been successful. Can anyone provide assistance on how I can achieve the desired ordering?