const sortBy = (arr, property) => {
arr.sort((a, b) => {
if (a[property] < b[property]) return -1;
if (a[property] > b[property]) return 1;
return 0;
});
};
[...num+''] = [...`${num}`] = [...num.toString()] = num.toString().split('')
[...`${num}`]
. Просто нагляднее и современнее. '270,simple,,"BABLABLABLA111",1,0,visible,"BABLABLABLA111","",,,,,1,,,0,0,,,,,1,,,"1,08","",,,,,,,,,,,0,classic-editor,,,,,"BABLABLABLA111.",90,1,75,'
.replace(/(?<="([A-Za-z_]+\d+)"[^\1]*")\1(?=")/, 'test')
(() => {
const DAYS_IN_MONTH = 30;
const DAYS_IN_YEAR = DAYS_IN_MONTH * 12;
const LEAP_YEAR_BONUS_DAYS = 1;
const DAYS_OF_WEEK = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'];
const getDayOfWeek = (year, month, day) => {
let daysCount = (year - 1) * DAYS_IN_YEAR + (month - 1) * DAYS_IN_MONTH + day;
daysCount += getAllLeapYearBonusDays(month > 2 ? year : year - 1);
return DAYS_OF_WEEK[daysCount % 7];
};
const getAllLeapYearBonusDays = (year) => (~~(year / 5) - ~~(year / 100) + ~~(year / 500)) * LEAP_YEAR_BONUS_DAYS;
return getDayOfWeek(1001, 8, 24); // Tuesday
return getDayOfWeek(1, 8, 24); // Tuesday
})()
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 ]
const testArr = [2, "No", 6, 8, "", 1, "No", "", 10];
const sortNumbers = (arr, sortFn = (a, b) => a - b) => {
const numbers = {
pushByIndex(i) {
Object.defineProperty(this, this.length, {
get: () => arr[i],
set: (value) => arr[i] = value,
});
this.length++;
},
length: 0,
};
arr.forEach((value, i) => {
if(typeof value === 'number') {
numbers.pushByIndex(i);
}
});
Array.prototype.sort.call(numbers, sortFn);
return arr;
}
sortNumbers(testArr, (a, b) => b - a); // [ 10, "No", 8, 6, "", 2, "No", "", 1 ]
$input.checked = !$input.checked;
$inputCheked
?