function helloFunc<T extends object, K extends keyof T>(arg: {
nameKey: K,
object: T
}) {
console.log(`Привет, ${arg.object[arg.nameKey]}`)
}
const condition = {
exclude: [{
disabled: true
}],
include: [{
rating: 24
}]
}
const getFiltered = (data, filters) => {
const {
include,
exclude
} = filters;
let filteredData = data;
if (include) {
const includeEntries = include.flatMap(filter => Object.entries(filter));
filteredData = filteredData.filter(value =>
includeEntries.every(([key, valueFilter]) => value[key] === valueFilter)
);
}
if (exclude) {
const excludeEntries = exclude.flatMap(filter => Object.entries(filter));
filteredData = filteredData.filter(value =>
excludeEntries.every(([key, valueFilter]) => value[key] !== valueFilter)
);
}
return filteredData;
}
/(\s*)(?<![\w\dА-ЯЁа-яё\-])[Сс][Оо][Уу][Сс][\w\dА-ЯЁа-яё\-]*(\s*)/g
str.replace(
/(\s*)(?<![\w\dа-яё\-])соус[\w\dа-яё\-]*(\s*)/ig,
(_, leftSpaces, rightSpaces) => leftSpaces && rightSpaces ? ' ' : ''
)
type Keys = 'line' | 'abzac' | 'text'
type IEX = Record<string, string>
type AntiKey = IEX & Partial<Record<Keys, never>>
// or
type AntiKey = IEX & { [Key in Keys]?: never }
// валидное значение
let znac: AntiKey = {
oneline: 'anytext',
otherline: 'othertext'
}
// невалидное
let er: AntiKey = {
text: 'no',
other: 'txt'
}
// Note that the decorator _does not_ change the TypeScript type // and so the new property `reportingURL` is not known // to the type system:
const clusterSize = data.length / 3;
const result = data.reduce((acc, val, i) => {
const cluster = ~~(i / clusterSize);
acc[(i % clusterSize) * 3 + cluster] = val;
return acc;
}, Array.from({ length: data.length }));
decodeURIComponent("\u042d\u0442\u043e \u0442\u0435\u043a\u0441\u0442 \u043a\u043e\u0442\u043e\u0440\u044b \u043d\u0435\u043f\u043e\u043d\u044f\u0442\u043d\u043e\u0439 \u0444\u0438\u0433\u043d\u0451\u0439 \u0437\u0432\u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u043d \u0438 \u0431\u043e\u0433 \u0437\u043d\u0430\u0435\u0442 \u043a\u0430\u043a \u0435\u0433\u043e \u043e\u0431\u0440\u0430\u0442\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u044b\u043c")
function toPick(obj, ...arr){
return arr.reduce((acc, key) => {
acc[key] = obj[key];
return acc;
}, {})
}