"123 фыва456 ячсм"
./(?:^|(?<=\s))\d{1,3}(?:\s[^\d\s]+(?:\d+[^\d\s]*)*)+/g
(() => {
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
})()
T[keyof T]
и передаёшь interface IUser {
name: string;
role: IRole;
}
string | IRole
.type Extractor<T, X> = (entry: T) => X;
const groupBy = <T, X>(
collection: T[],
mapper: Extractor<T, X>
): Map<X, T[]> => collection.reduce((accumulator, entry) => {
const key = mapper(entry);
if (accumulator.has(key)) {
accumulator.get(key)!.push(entry);
return accumulator;
}
accumulator.set(key, [entry]);
return accumulator;
}, new Map<X, T[]>());
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 ]
function f(someObj: T1, someEnum: typeof E1): string;
function f(someObj: T2, someEnum: typeof E2): string;
function f(someObj: T1 | T2, someEnum: typeof E1 | typeof E2): string {
const typedSomeObj = someObj as T1 & T2;
return typedSomeObj[someEnum.a];
}
$input.checked = !$input.checked;
$inputCheked
?