Подскажите, как можно отрефакторить такой метод фильтрации:
filterTasks(tasks) {
switch (this.state.currentFilter) {
case TaskList.filters.description: {
const sortedTasks = tasks.sort((a, b) => {
return a.description > b.description;
});
if (this.state.isFilterReverse) {
return sortedTasks.reverse();
}
return sortedTasks;
}
case TaskList.filters.status: {
const sortedTasks = tasks.sort((a, b) => {
return a.status > b.status;
});
if (this.state.isFilterReverse) {
return sortedTasks.reverse();
}
return sortedTasks;
}
case TaskList.filters.task: {
const sortedTasks = tasks.sort((a, b) => {
return a.name > b.name;
});
if (this.state.isFilterReverse) {
return sortedTasks.reverse();
}
return sortedTasks;
}
case TaskList.filters.priority: {
const sortedTasks = tasks.sort((a, b) => {
return a.priority > b.priority;
});
if (this.state.isFilterReverse) {
return sortedTasks.reverse();
}
return sortedTasks;
}
default:
return tasks;
}
}