data.filter(v => filterKeys.every(k => v.weather[k]));
const data = [{
city: 'Первый',
weather: {
blizzard: false,
cloudy: true,
metorite: true,
}
},
{
city: 'Второй',
weather: {
blizzard: true,
cloudy: true,
metorite: true,
}
},
{
city: 'Третий',
weather: {
blizzard: true,
cloudy: false,
metorite: false,
}
}
];
const filterKeys = ['blizzard', 'cloudy'];
const a = 6;
const b = 2;
const [min, max] = a < b ? [a, b] : [b, a];
const result = [];
for(let i = min; i <= max; i++) {
result.push(i);
}
result.join(' ');
const setProtection = (name = '', style = '', icon = '') => ({ name, style, icon });
const all = [{id:0}, {id:1}, {id:2}];
const local = [{movieId:1}];
const result = all.map((am) => {
const lm = local.find((m) => m.movieId === am.id)
return lm ?? am;
});
а можешь, пожалуйста, уточнить насчет возвращаемого значения return lm ?? am;
const menuSelectors = ['.cross', '.cart_popup', '.popup', '.cart_overlay', 'progress'];
const toggleMenu = (show) => {
menuSelectors.forEach((s) => document.querySelector(s).classList.toggle('active', show));
}
const showMenu = () => {
document.querySelector('.header_feedback').style.zIndex = '82';
toggleMenu(true);
};
const hideMenu = () => {
setTimeout(() => document.querySelector('.header_feedback').style.zIndex = '80', 300);
toggleMenu(false);
};
document.querySelector('.burger_block').addEventListener('click', showMenu);
document.querySelector('.cross').addEventListener('click', hideMenu);
document.querySelector('.cart_overlay').addEventListener('click', hideMenu);
const getMostCommonSymbol = (str) => {
const sortedSymbols = str.split('').sort().join('');
const countedSymbols = [...sortedSymbols.matchAll(/(.)\1*/g)];
return countedSymbols.reduce(
(acc, [row, symbol]) =>
acc.count < row.length ? { symbol, count: row.length } : acc,
{ symbol: null, count: 0 }
);
}
getMostCommonSymbol('asdasda')
function waitForElementAndClick(selectors, checkInterval = 100) {
return new Promise((resolve) => {
let intervalId = setInterval(() => {
if (document.querySelector(selectors) != null) {
document.querySelector(selectors).click()
clearInterval(intervalId)
resolve()
}
}, checkInterval)
});
}
const menuQuerySelector = (selectors) => selectors.map((s) => menuWrapper.querySelector(s));
const buttonSelectors = ['.b1', '.b2', '.b3', '.b4', ...];
const [button1, button2, button3, button4, ...] = menuQuerySelector(buttonSelectors);
{
const max1 = 9;
const max2 = 30; // max of two nums
let cur = max2 / max1;
const inc = cur;
const len = 3;
const log = (a, b) => {
console.log(b > -Infinity ? `a: ${` ${a}`.slice(-len)} | b: ${` ${b}`.slice(-len)}` : `a: ${` ${a}`.slice(-len)} |`)
}
log(0, 0);
for(let i = 1, j = 1; i < max2; i++) {
const nums = [i];
if(i >= cur) {
nums.push(j);
j++;
cur += inc;
}
log(...nums);
}
log(max2, max1);
}
const SECTIONS = [
'top',
'bottom',
'head',
'shoes',
'bag',
'accs',
];
const prepareShareItems = () => {
const { person, items } = store.getState().globals;
const result = SECTIONS.reduce((acc, section) => {
const personSection = person[section];
const { slide } = personSection;
const itemId = personSection.list[slide];
const item = items.find((item) => item.id === itemId);
acc[section] = item?.image;
return acc;
}, {});
return result;
}
const button = document.querySelector('.test')
const updateProp = () => {
const confirmResult = confirm(
'Вы действительно хотите изменить значение ключа у объекта или получить данный объект в консоль?'
);
if (!confirmResult) {
console.log('Вы отменили данное действие');
return;
}
const promptResult1 = prompt('Введите желаемый ключ');
if (!promptResult1.includes('_')) {
const promptResult2 = prompt('Введите желаемое значение');
proxy[promptResult1] = promptResult2
}
console.log(proxy[promptResult1])
}
button.addEventListener('click', updateProp)
const person = {
name: 'Maxim',
job: 'Junior Fronted-Developer',
age: 15
}
const handler = {
get(target, props) {
let arr = props.split('_').map((el) => (`${el}: ${target[el] ?? 'Такого ключа не существует'}`));
return arr.join(', ');
},
set(target, key, prop) {
if (!target[key]) {
console.log('Не верная запись');
return;
}
if (prop === null) {
console.log('Значение не указано');
return;
}
const confirmResult = confirm(
`Подтвердить изменение данного ключа (${key}) на значение ${prop}?`
)
if (!confirmResult) {
console.log('Действие отменено');
return;
}
switch (key) {
case 'age':
if (prop <= 0 || prop > 100) {
console.log(`Слишком ${prop > 100 ? 'высокий' : 'маленький'} возраст`);
return;
}
target[key] = prop;
return;
default:
target[key] = prop;
}
}
}
const proxy = new Proxy(person, handler);
const rCount = Array.prototype.reduce.call(str, (acc, letter) => {
if (rX.includes(letter)) {
acc.X++;
} else if (rO.includes(letter)) {
acc.O++;
}
return acc;
}, { X: 0, O: 0 });
const rCount = Array.prototype.reduce.call(str.toLowerCase(), (acc, letter) => {
switch(letter) {
case 'x':
acc.X++;
break;
case 'o':
acc.O++;
break;
}
return acc;
}, { X: 0, O: 0 });
const hasPairSum = (nums, desiredValue) => {
if(nums.length < 2) {
return false;
}
const [firstNum, ...tailNums] = nums;
const hasDesiredValue = tailNums.some((num) => firstNum + num === desiredValue);
return hasDesiredValue || hasPairSum(tailNums, desiredValue);
};