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 ? ' ' : ''
)
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;
}, {})
}
const findWhere = (shelf, book) => {
for (let i = 0; i < shelf.length; i++) {
let flag = true;
for (let [key, value] of Object.entries(book)) {
if (shelf[i][key] !== value) {
flag = false;
break;
}
}
if (flag) {
return shelf[i];
}
}
return null;
};
n = 2
[0,1,1] => true
[1,1,0] => false
const arr = [
[0,0,0,0],
[1,0,0,0],
[0,1,0,0],
[0,0,0,0],
];
const n = 2;
const inRow = (arr, oneMax) => {
const { length } = arr;
if(oneMax > length) {
return false;
}
const oneCounter = {
'--': 0,
'||': 0,
'\\': {
top: 0,
bot: 0,
},
'//': {
top: 0,
bot: 0,
},
};
const check = (value, counter, key) => {
if(value === 1) {
counter[key]++;
if(counter[key] === oneMax) {
return true;
}
} else {
counter[key] = 0;
}
return false;
}
for(let i = 0; i < length; i++) {
for(let j = 0; j < length; j++) {
if(
check(arr[i][j], oneCounter, '--') ||
check(arr[j][i], oneCounter, '||')
) {
return true;
}
}
oneCounter['--'] = 0;
oneCounter['||'] = 0;
}
const maxDiags = length - n + 1;
const last = length - 1;
for(let i = 0, maxJ = length; i < maxDiags; i++, maxJ--) {
for(let j = 0; j < maxJ; j++) {
if(
check(arr[j][i + j], oneCounter['\\'], 'top') ||
check(arr[i + j][j], oneCounter['\\'], 'bot') ||
check(arr[j][last - (i + j)], oneCounter['//'], 'top') ||
check(arr[i + j][last - j], oneCounter['//'], 'bot')
) {
return true;
}
}
oneCounter['\\'].top = 0;
oneCounter['\\'].bot = 0;
oneCounter['//'].top = 0;
oneCounter['//'].bot = 0;
}
return false;
}
inRow(arr, n)
const getValue = (obj, keys) => keys.reduce((acc, key) => acc?.[key], obj);
const d = new Date('2021-11-03T23:24:00.000Z');
d.setMinutes(d.getMinutes() + 1349);
const getAverageScores = () => {
const initialValues = {avg: 0, n: 0};
return data.reduce(function (initialValues, data) {
const avg = (data.value + initialValues.n * initialValues.avg) / (initialValues.n + 1)
const n = initialValues.n + 1
return {
avg,
n
}
}, initialValues).avg;
}
return data.reduce((acc, { value }) => acc + value, 0) / data.length;
[fName.value, lName.value, ab.value, eColor.value] =
row[row.rowIndex - 1].cells.map(c => c.textContent);
const obj = (() => {
let priv_count = 0;
return {
get count() {
return priv_count;
}
}
})();