<select id="event"></select>
<select id="dates"></select>
const events = [
{ name: '...', dates: [ ... ] },
{ name: '...', dates: [ ... ] },
...
];
const eventEl = document.querySelector('#event');
const datesEl = document.querySelector('#dates');
eventEl.innerHTML = events
.map((n, i) => `<option value="${i}">${n.name}</option>`)
.join('');
eventEl.addEventListener('change', function() {
datesEl.innerHTML = events[this.value].dates
.map(n => `<option>${n}</option>`)
.join('');
});
eventEl.dispatchEvent(new Event('change'));
const getDuplicates = (arr, key) => Array
.from(arr.reduce((acc, { [key]: n }) => acc.set(n, -~acc.get(n)), new Map))
.filter(n => n[1] > 1)
.map(n => n[0]);
const duplicates = getDuplicates(arr, 1);
const getDuplicates = (arr, key = n => n) => Array
.from(arr.reduce((acc, n) => (n = key(n), acc.set(n, acc.has(n))), new Map))
.reduce((acc, n) => (n[1] && acc.push(n[0]), acc), []);
const duplicates = getDuplicates(arr, n => n[1]);
const getDuplicates = arr =>
[...arr.reduce((acc, n) => (
acc[+acc[0].has(n)].add(n),
acc
), [ new Set, new Set ])[1]];
const duplicates = getDuplicates(arr.map(n => n[1]));
Не поможет ли lodash?
const duplicates = _(arr)
.map(n => n[1])
.groupBy()
.filter(n => n.length > 1)
.map(n => n[0])
.value();
async function processData(data) {
const result = [];
for (const { id, k } of data) {
result.push(k ? await api.getData(id) : id);
}
return result;
}
function processData(data) {
return Promise.all(data.map(({ id, k }) => k ? api.getData(id) : id));
}
function render(message) {
const p = document.createElement('p');
p.textContent = message;
windowChatUser1.append(p);
windowChatUser2.append(p.cloneNode(true));
}
function render(message) {
const html = `<p>${message}</p>`;
windowChatUser1.insertAdjacentHTML('beforeend', html);
windowChatUser2.insertAdjacentHTML('beforeend', html);
}
callbacks: {
open() {
$(window).trigger('resize');
},
},
Удаление перехватывающего обработчика никак не затрагивает не-перехватывающюю версию этого же обработчика, и наоборот.
const mod = (a, b) => ((a % b) + b) % b;
// или
const mod = (a, b) => a - (b * Math.floor(a / b));
console.log([ 12, 367, -54, 789, -567 ].map(n => mod(n, 360)));
arr.reduce((max, n) => +n < +max ? max : n, -Infinity)
data.flatMap(item => item.events.flatMap(event => event.params.map(param => ({
name: item.name,
event_key: event.event_key,
...param,
}))))
document.querySelectorAll('.heading').forEach(n => {
const words = n.innerText.split(' ');
const center = words.length / 2 | 0;
words.splice(center + 2, 0, '</span>');
words.splice(center - 1, 0, '<span>');
n.innerHTML = words.join(' ');
});
function fadeToggle(selector, delay) {
let index = -1;
return setInterval($items => {
$items.eq(index).fadeOut('slow');
index = (index + 1) % $items.length;
$items.eq(index).fadeIn('slow');
}, delay, $(selector));
}
const intervalId = fadeToggle('.sloi', 1000);
for (let i = begin; i <= end; i++) {
let str = '';
if (!(i % 3)) {
str += 'Fizz';
}
if (!(i % 5)) {
str += 'Buzz';
}
console.log(str || i);
}
console.log(Array.from({ length: end - begin + 1 }, (_, i) => {
i += begin;
return (i % 3 ? '' : 'Fizz') + (i % 5 ? '' : 'Buzz') || i;
}).join('\n'));
// или
for (let i = begin; i <= end; console.log('FizzBuzz'.slice(i % 3 && 4, 4 << !(i % 5)) || i), i++) ;