const fourValues = four.map(Object.values);
const result = three.map(n => {
const values = Object.values(n);
const intersections = fourValues.filter(m => values.every(v => m.includes(v)));
return `${values} - ${intersections.length
? `входит в / ${intersections.map(m => `${m}`).join(' / ')} /`
: 'нет вхождений'}`;
});
$('.bakeries-slider').each(function() {
$('.bakeries-slider__span', this).text(i => `${i + 1}.`);
});
for (const n of document.querySelectorAll('.bakeries-slider')) {
n.querySelectorAll('span').forEach((m, i) => m.innerText = ++i + '.');
}
[].forEach.call(document.getElementsByClassName('bakeries-slider'), n => {
const slides = n.getElementsByTagName('span');
for (let i = 0; i < slides.length; i++) {
slides[i].textContent = ''.concat(-~i, '.');
}
});
$('#m_prev').click
и $('#m_next').click
за пределы $('.norutyun img').click
. $('#sortable').sortable({
stop() {
const values = $('input[name="slider-id"]', this).get().map(n => n.value);
},
});
const key = 'workplace';
const values = [ 'office', 'hotel' ];
const result = arr.filter(n => values.includes(n[key]));
// или
const result = values.flatMap(function(n) {
return this[n] ?? [];
}, arr.reduce((acc, n) => ((acc[n[key]] = acc[n[key]] ?? []).push(n), acc), {}));
// или
const filter = (arr, key, values) =>
arr.filter(function(n) {
return this.has(n[key]);
}, new Set(values));
const result = filter(arr, key, values);
#list-case
вы назначаете обработчики клика всем существующим .img
и .show
, а не только свежесозданным. Если срабатывает два (или четыре, или шесть, или...) обработчика, которые выполняют toggleClass, то конечное состояние от начального отличаться не будет. Отсюда ваше кажущееся "не работает"..case
, делайте это один раз, используя делегирование:$('#list-case')
.on('click', '.img', function() {
$(this).closest('.case').remove();
})
.on('click', '.show', function() {
$(this).toggleClass('none').closest('.case').find('.case-bottom').toggleClass('invise');
});
const placeholders = [ 'hello, world!!', 'fuck the world', 'fuck everything' ];
const delay = 200;
const input = document.querySelector('input');
function interval(arr, delay, callback) {
let i = -1;
return arr.length
? setInterval(() => callback(arr[i = -~i % arr.length]), delay)
: null;
}
const intervalId = interval(placeholders, delay, n => input.placeholder = n);
// хотим остановить, делаем так: clearInterval(intervalId);
function interval(arr, delay, callback) {
let timeoutId = null;
arr.length && (function step(i) {
timeoutId = setTimeout(() => {
callback(arr[i]);
step((i + 1) % arr.length);
}, delay);
})(0);
return () => clearTimeout(timeoutId);
}
const stop = interval(
placeholders,
delay,
Element.prototype.setAttribute.bind(input, 'placeholder')
);
// хотим остановить, делаем так: stop();
return false;
toggle дважды начинает срабатывать
const comparators = [
[ 'city', (itemVal, filterVal) => itemVal === filterVal ],
[ 'title', (itemVal, filterVal) => itemVal.includes(filterVal) ],
[ 'type', (itemVal, filterVal) => itemVal.includes(filterVal) ],
];
const filteredArr = arr.filter(n => comparators.every(([ k, f ]) => f(n[k], filter[k])));
document.querySelectorAll('.group-options__item').forEach(n => {
const input = (n.closest('.group-options') ?? n).querySelector('[data-prop]');
if (input) {
input.checked = true;
}
});
function getStrings(str) {
const str1 = str.match(/\(.+?\)/g)?.find(n => /\d/.test(n)) ?? '';
return {
str1: str1.slice(1, -1),
str2: str.replace(str1, ''),
};
}
const select = document.querySelector('здесь селектор вашего select\'а');
const addValToText = option => addText(option, getVal(option));
const getVal = option => option.value;
// или
const getVal = option => option.getAttribute('value');
// или
const getVal = option => option.attributes.value.value;
const addText = (option, text) => option.text += text;
// или
const addText = (option, text) => option.textContent = option.textContent.concat(text);
// или
const addText = (option, text) => option.innerText = `${option.innerText}${text}`;
// или
const addText = (option, text) => option.append(text);
// или
const addText = (option, text) => option.insertAdjacentText('beforeend', text);
// или
const addText = (option, text) => option.appendChild(document.createTextNode(text));
// или
const addText = (option, text) => option.insertBefore(new Text(text), null);
Array.prototype.forEach.call(select, addValToText);
// или
select.querySelectorAll('option').forEach(addValToText);
// или
for (const n of select.options) {
addValToText(n);
}
// или
for (let i = 0; i < select.children.length; i++) {
addValToText(select.children[i]);
}
str.replace(/:$/, '')
// или
str.match(/[^:]+:[^:]+/)[0]
// или
str.match(/[^:]+/g).slice(0, 2).join`:`
// или
str.split(':', 2).join(':')
// или
str.slice(0, str.length - (str.slice(-1) === ':'))
$('.progress__item').each(function() {
const $this = $(this);
const $progressBar = $this.find('.progress__bar');
const $value = $this.find('.progress__value');
const value = $progressBar.data('progress-value');
$progressBar.width(`${value}%`);
$({ value: 0 }).animate({
value,
}, {
duration: 1000,
step: val => $value.text(`${val.toFixed(1)} %`),
});
});