['18 February 2021', 'yesterday', 'today']
['today', 'yesterday', '18 February 2021']
['18 February 2021', 'yesterday', 'today'].sort((a, b) => {
if (a === 'today') return -1;
if (a === 'yesterday') return 0;
return 1;
});
const getPosition = (str) => {
switch (str) {
case 'today':
return 0;
case 'yesterday':
return 1;
case '18 February 2021':
return 2;
default:
return 3;
}
};
['18 February 2021', 'asdasda', 'yesterday', 'today'].sort((a, b) => getPosition(a) - getPosition(b));