如何摆脱函数中的代码重复?(如果块是明显的重复)
function sortStrings(arr, param = 'asc') {
const arrCopy = [...arr];
if (param === 'asc') {
arrCopy.sort((a, b) => a.localeCompare(b, ['ru', 'eng'], { caseFirst: 'upper' }));
}
if (param === 'desc') {
arrCopy.sort((a, b) => -a.localeCompare(b, ['ru', 'eng'], { caseFirst: 'lower' }));
}
return arrCopy;
}