const testArr = [2, "No", 6, 8, "", 1, "No", "", 10];
const sortNumbers = (arr, sortFn = (a, b) => a - b) => {
const numbers = [];
arr.forEach((value, i, target) => {
if (typeof value === 'number') {
Object.defineProperty(numbers, numbers.length, {
get: () => target[i],
set: (v) => target[i] = v,
});
}
});
numbers.sort(sortFn);
return arr;
}
console.log(sortNumbers(testArr, (a, b) => b - a)); // [ 10, "No", 8, 6, "", 2, "No", "", 1 ]
Зачем ее ограничивать