событие не срабатывает
const oldSetDate = $.datepicker._setDate;
$.datepicker._setDate = function(...args) {
oldSetDate.apply(this, args);
setTimeout(() => args[0].input.find('.ui-datepicker-current-day').click());
};
p.process-block__stage-number.active I
p.process-block__stage-number II
p.process-block__stage-number III
p.process-block__stage-number IV
button.process-block__btn(data-change=-1)
span
b prev
button.process-block__btn(data-change=+1)
span
b next
document.addEventListener('click', function(e) {
const button = e.target.closest('[data-change]');
if (button) {
const blocks = [...document.querySelectorAll('.process-block__stage-number')];
let active = blocks.findIndex(n => n.classList.contains('active'));
blocks[active].classList.remove('active');
active = Math.max(0, Math.min(blocks.length - 1, active + +button.dataset.change));
blocks[active].classList.add('active');
}
});
проблема в том, что при клике по какому-либо элементу подМЕНЮ, первый, элемент который задавался по умолчанию не сбрасывает стиль
$('ul#topnav li span a').click(function(e) {
e.stopPropagation();
...
const [ key ] = Object
.entries(data)
.reduce((max, [ k, { Number_of_Something: v } ]) => {
return max[1] > v ? max : [ k, v ];
}, [ null, -Infinity ]);
const key = (Object
.entries(data)
.sort((a, b) => b[1].Number_of_Something - a[1].Number_of_Something)
.shift() || [ null ])
.shift();
let key = null;
let max = -Infinity;
for (const k in data) {
if (data.hasOwnProperty(k) && data[k].Number_of_Something > max) {
key = k;
max = data[k].Number_of_Something;
}
}
const max = Math.max(...Object.values(data).map(n => n.Number_of_Something));
const key = Object.keys(data).find(k => data[k].Number_of_Something === max) || null;
<div class="out"></div>
<button class="btn">click me</button>
const images = [ '...', '...', /* ... */ ];
const SHOW_MORE = 2;
document.querySelector('.btn').addEventListener('click', e => {
document.querySelector('.out').insertAdjacentHTML('beforeend', images
.splice(0, SHOW_MORE)
.map(n => `<div class="outImg"><img src="${n}"></div>`)
.join('')
);
e.target.disabled = !images.length;
});
$('ur_login')
$('ur_password')
только начал учить AJAX и PDO
const table = document.querySelector('.table-price table');
.highlight-min {
color: green;
font-weight: bold;
}
.highlight-max {
color: red;
font-weight: bold;
}
table.querySelectorAll('tr').forEach(n => {
const td = Array
.from(n.querySelectorAll('td:not(.logo-table)'), m => [ m, +m.innerText.match(/\d+/) ])
.sort((a, b) => a[1] - b[1])[0][0];
td.classList.add('highlight-min');
});
for (const { cells: [ , ...cells ] } of table.rows) {
const [ tds ] = cells.reduce((max, n) => {
const val = parseInt(n.textContent);
if (val > max[1]) {
max = [ [], val ];
}
if (val === max[1]) {
max[0].push(n);
}
return max;
}, [ [], -Infinity ]);
tds.forEach(n => n.classList.add('highlight-max'));
}
const className = 'класс элементов, чьи id вам надо получить';
const elems = document.querySelectorAll(`.${className}`);
// или
const elems = document.getElementsByClassName(className);
const getId = el => el.id;
// или
const getId = el => el.getAttribute('id');
// или
const getId = el => el.attributes.id.value;
const ids = Array.from(elems, getId);
// или
const ids = [].map.call(elems, getId);
// или
const ids = [];
for (const n of elems) {
ids.push(getId(n));
}
// или
const ids = [];
for (let i = 0; i < elems.length; i++) {
ids[i] = getId(elems[i]);
}
const result = Object.values(arr.reduce((acc, n) => (
acc[n.id] = n.checked ? n : (acc[n.id] || n),
acc
), {}));
const result = arr.reduce((acc, n) => {
const i = acc.findIndex(m => m.id === n.id);
if (!~i || (!acc[i].checked && n.checked)) {
acc.push(n);
if (~i) {
acc.splice(i, 1);
}
}
return acc;
}, []);
// или
const result = Object
.values(arr.reduce((acc, n, i) => (
(!acc[n.id] || (!acc[n.id][0].checked && n.checked)) && (acc[n.id] = [ n, i ]),
acc
), {}))
.sort((a, b) => a[1] - b[1])
.map(n => n[0]);
[...document.querySelectorAll('.buy > i')]
.filter((n, i, a) => i !== a.findIndex(m => m.innerText === n.innerText))
.forEach(n => n.parentNode.style.display = 'none');
const grouped = Array
.from(document.querySelectorAll('.buy > i'), n => [ n.parentNode, n.innerText ])
.reduce((acc, n) => ((acc[n[1]] = acc[n[1]] || []).push(n[0]), acc), {});
Object.values(grouped).forEach(n => n.forEach((m, i) => m.hidden = !!i));
.hidden {
display: none;
}
const unique = new Set();
for (const n of document.querySelectorAll('.buy > i')) {
if (unique.has(n.innerText)) {
n.parentNode.classList.add('hidden');
} else {
unique.add(n.innerText);
}
}
people.filter((n, i, a) => n.country && i === a.findIndex(m => m.country === n.country))
people.filter((n, i, a) => n.country && n === a.find(m => m.country === n.country))
people.filter(function({ country: n }) {
return n && !(this[n] = this.hasOwnProperty(n));
}, {})
Object.values(people.reduce((acc, n) => (n.country && (acc[n.country] = n), acc), {}))
[...people.reduce((acc, n) => n.country ? acc.set(n.country, n) : acc, new Map).values()]
Array.from(
new Set(people.map(n => n.country).filter(Boolean)),
n => people.find(m => m.country === n)
)
if ( typeof arr[i] === 'number' ) { x*= arr[i];
arr[i + 1]
окажется строкой? Сначала надо проверить всё, а уже потом вычислять (если потребуется) объединённое значение:function bullshit(arr) {
if (arr.every(n => typeof n === 'number')) {
return arr.reduce((acc, n) => acc * n, 1);
}
if (arr.every(n => typeof n === 'string')) {
return arr.join('');
}
return null;
}
bullshit([ 1, 2, 3 ]) // 6
bullshit([ 'a', 'b', 'c' ]) // 'abc'
bullshit([ 1, '!' ]) // null
function bullshit(arr) {
const count = arr.reduce((acc, n) => {
const type = typeof n;
acc[type] = (acc[type] || 0) + 1;
return acc;
}, {});
switch (arr.length) {
case count.number: return arr.reduce((acc, n) => acc * n, 1);
case count.string: return arr.join('');
default: return null;
}
}
Object.fromEntries(Object
.entries(obj)
.sort((a, b) => a[0] - b[0])
.reduce((acc, [ k, v ], i, a) => (
i && k - a[~-i][0] === 1 || acc.push([ k, 0 ]),
acc[~-acc.length][1] += v,
acc
), [])
)