<a data-problem="value1">
<a data-problem="value2">
<a data-problem="value1|value2">
$('.problem').change(function() {
const problems = $(':checked', this)
.get()
.map(({ dataset: { type, problem } }) => ({ type, problem }));
$(this)
.closest('.remont')
.find('.price__item')
.hide()
.filter((i, { dataset: d }) =>
problems.some(p => d.type === p.type && d.problem.includes(p.problem))
)
.show();
}).change();
$('.problem').change(({ target: t }) => {
const attrsSelector = [ 'type', 'problem' ]
.map(n => `[data-${n}="${t.dataset[n]}"]`)
.join('');
$(`.price-problem ${attrsSelector}`).toggle(t.checked);
}).find('input').change();
$('.item img').wrap(function() {
return '<a href="' + $(this).attr('src') + '"></a>';
});
document.querySelectorAll('.item img').forEach(n => {
n.outerHTML = `<a href="${n.attributes.src.value}">${n.outerHTML}</a>`;
});
for (const n of document.querySelectorAll('.item img')) {
const a = document.createElement('a');
a.href = n.getAttribute('src');
n.after(a);
a.append(n);
}
const markersData = [
{ position: { lat: ..., lng: ... }, content: '...' },
{ position: { lat: ..., lng: ... }, content: '...' },
...
];
const infoWindow = new google.maps.InfoWindow();
const markers = markersData.map(({ position, content }) => {
const marker = new google.maps.Marker({ position, map });
marker.addListener('click', () => {
infoWindow.setContent(content);
infoWindow.open(map, marker);
});
return marker;
});
null
):const setActiveIcon = marker => markers.forEach(n => n.setIcon(n === marker ? iconActive : icon));
function createTree(arr) {
const tree = Object.fromEntries(arr.map(({ parts, ...n }) => [ n.id, n ]));
arr.forEach(n => tree[n.id].children = n.parts?.map(m => tree[m]) ?? []);
return Object.values(tree).filter(n => arr.every(m => !m.parts?.includes(n.id)));
}
<div class="wrapper">
.const containerSelector = '.wrapper';
const headerSelector = '.request__nav__item';
const contentSelector = '.request__field';
const activeClass = 'active';
$(containerSelector).on('click', headerSelector, function(e) {
const $headers = $(headerSelector, e.delegateTarget);
const index = $headers.index(this);
$headers.removeClass(activeClass).eq(index).addClass(activeClass);
$(contentSelector, e.delegateTarget).hide().eq(index).fadeIn();
}).each(function() {
$(headerSelector, this).first().click();
});
$('a').click(function() {
const $tabs = $('.splCont');
const $tab = $tabs.eq($(this).index()).toggle('normal');
$tabs.not($tab).hide('normal');
return false;
});
const toSeconds = str => str
.split(':')
.reverse()
.reduce((acc, n, i) => acc + n * (60 ** i), 0);
const sumDiagonals = matrix =>
matrix.reduce((acc, n, i) => {
acc.principal += n[i];
acc.secondary += n[n.length - i - 1];
return acc;
}, {
principal: 0,
secondary: 0,
});
numbers.filter(n => !objects.some(m => m.number === n))
numbers.filter(function(n) {
return !this.has(n);
}, new Set(objects.map(n => n.number)))
numbers.filter(((nums, n) => !nums.includes(n)).bind(null, objects.map(n => n.number)))
Object.values(objects.reduce(
(acc, n) => (delete acc[n.number], acc),
numbers.reduce((acc, n) => (acc[n] = n, acc), {})
))
Array.from(objects.reduce(
(acc, n) => (acc.delete(n.number), acc),
new Map(numbers.map(n => [ n, n ]))
).values())
const newArr = [...arr]
.sort((a, b) => a.name.localeCompare(b.name) || (a.price - b.price))
.filter((n, i, a) => n.name === a[i - 1]?.name);
const newArr = [...arr]
.sort((a, b) => a.name.localeCompare(b.name) || (a.price - b.price))
.filter((n, i, a) => n.name === a[i - 1]?.name || n.name !== a[i + 1]?.name);
const newArr = [...arr]
.sort((a, b) => a.price - b.price)
.filter((n, i, a) => n !== a.find(m => m.name === n.name));
const newArr = [...arr].sort((a, b) => a.price - b.price);
Object
.values(newArr.reduce((acc, n) => ((acc[n.name] ??= []).push(n), acc), {}))
.forEach(n => n.length !== 1 && newArr.splice(newArr.indexOf(n[0]), 1));
const mustStay = n => n !== null;
.const newArr = arr.map(n => ({
...n,
array2: n.array2.filter(mustStay),
}));
arr.forEach(n => n.array2.reduceRight((_, n, i, a) => mustStay(n) || a.splice(i, 1), 0));
// или
for (let i = 0; i < arr.length; i++) {
const a = arr[i].array2;
a.splice(0, a.length, ...a.filter(mustStay));
}
// или
for (const { array2: a } of arr) {
let numDeleted = 0;
for (const [ i, n ] of a.entries()) {
a[i - numDeleted] = n;
numDeleted += !mustStay(n);
}
a.length -= numDeleted;
}
const columnIndex = {
color: 0,
fruit: 1,
};
function filter() {
const filters = Object.entries(Array
.from(document.querySelectorAll('.list-group :checked'))
.reduce((acc, n) => ((acc[n.name] ??= []).push(n.value), acc), {})
);
document.querySelectorAll('table tbody tr').forEach(n => {
n.style.display = filters.some(([ k, v ]) => !v.includes(n.cells[columnIndex[k]].innerText))
? 'none'
: 'block';
});
}
document.querySelectorAll('.list-group').forEach(n => n.addEventListener('change', filter));
function getDays(year, month) {
const days = [];
const d = new Date(year, month, 1);
let week = 1;
while (d.getMonth() === month) {
const date = d.getDate();
const day = d.getDay();
days.push({
day: date,
weeknumber: (day === 1 || date === 1) ? week : false,
weekday: d.toLocaleString('en-US', { weekday: 'short' }),
});
d.setDate(date + 1);
week += !day;
}
return days;
}
text.match(RegExp(str, 'g'))?.length ?? 0
text.split(str).length - 1
const flatObj = obj =>
Object.entries(obj).reduce((acc, [ k, v ]) => (
v instanceof Object && !Array.isArray(v)
? Object.assign(acc, flatObj(v))
: acc[k] = v,
acc
), {});