function getDate(day, year = new Date().getFullYear()) {
const date = new Date(year, 0, day);
return [
date.getDate(),
[
'январь', 'февраль', 'март', 'апрель', 'май', 'июнь',
'июль', 'август', 'сентябрь', 'октябрь', 'ноябрь', 'декабрь'
][date.getMonth()],
[ 'вс', 'пн', 'вт', 'ср', 'чт', 'пт', 'сб' ][date.getDay()],
].join(' ');
}
getDate(115, 2019) // "25 апрель чт"
const getDate = (day, year = new Date().getFullYear()) =>
new Date(year, 0, day).toLocaleString('ru-RU', {
day: 'numeric',
month: 'long',
weekday: 'short',
});
getDate(115, 2019) // "чт, 25 апреля"
.close-panel
, чтобы только что удалённый класс не добавлялся обратно (при обработке события в родительском элементе):$('.close-panel').on('click', function(e) {
e.stopPropagation();
$('.add-caption').removeClass('active');
});
.close-panel
, а в обработчике клика по .add
добавляйте или убирайте класс в зависимости от того, откуда пришло событие:$('.add').on('click', function(e) {
$('.add-caption').toggleClass('active', !$(e.target).hasClass('close-panel'));
});
const toDelX = new Set;
const toDelY = new Set;
X.forEach((n, i) => {
if (X2.includes(n) && Y2.includes(Y[i])) {
toDelX.add(n);
toDelY.add(Y[i]);
}
});
X2.splice(0, X2.length, ...X2.filter(n => !toDelX.has(n)));
Y2.splice(0, Y2.length, ...Y2.filter(n => !toDelY.has(n)));
let autoplayInterval = null;
function startAutoplay() {
if (!autoplayInterval) {
autoplayInterval = setInterval(plusSlide, 1000);
}
}
function stopAutoplay() {
clearInterval(autoplayInterval);
autoplayInterval = null;
}
function GetFaqAriaExpand(el) {
var fa = $(el).attr('aria-expanded');
...
var fa = GetFaqAriaExpand(this);
var fa = GetFaqAriaExpand.call(this);
$('.radio-input').parent('p').text((i, text) => text.replace('Какой-то ', ''))
$(this).parent('.card-header')
card-header
? - если нет, вызывайте parent без параметра. Или может быть класс есть, но элемент не родительский, а находится выше? - тогда замените parent на closest. Promise.all(rcs.map((residential, i) => {
return new Promise(resolve => {
setTimeout(() => {
...
resolve();
}, i * 50);
});
}).then(() => {
...
});
async setMarkers(rcs) {
for (const residential of rcs) {
await new Promise(resolve => setTimeout(resolve, 50));
...
}
...
}
const sort = {
str: (a, b) => a.text().localeCompare(b.text()),
num: (a, b) => parseInt(a.text(), 10) - parseInt(b.text(), 10),
};
<button class="sort" data-field="age" data-type="num">Сортировать по возрасту</button>
<button class="sort" data-field="name" data-type="str">Сортировать по имени</button>
$('.sort').click(function() {
const
$this = $(this),
data = $this.data(),
compare = sort[data.type],
field = `.${data.field}`,
order = +data.order || 1;
$('.block')
.sort((a, b) => order * compare($(field, a), $(field, b)))
.appendTo('.cont');
$this.data('order', order * -1);
});
$list.find('input').click(e => e.stopPropagation());
if (!$(e.target).is('input')) {
$list.hide();
}
.slice(1)
там, где работаете со строками таблицы. Т.е., вместо$('#data tbody tr').hide();
$('#data tbody tr').slice(0, rowsShown).show();
$('#data tbody tr').slice(1).hide().slice(0, rowsShown).show();
$('#data tbody tr').css('opacity',...
$('#data tbody tr').slice(1).css('opacity',...
str.match(/rgb\(.*\)/).pop().match(/\d+/g)
str.match(/rgb\((.*)\)/).pop().split(', ')
projectTechnologies.innerHTML = technologyHandler(dataTechnologies).map((el) => el);
projectTechnologies.innerHTML = technologyHandler(dataTechnologies).map(n => n.outerHTML).join('');
// или
technologyHandler(dataTechnologies).forEach(n => projectTechnologies.appendChild(n));
// или
for (const n of technologyHandler(dataTechnologies)) {
projectTechnologies.insertAdjacentElement('beforeend', n);
}
// или
projectTechnologies.append(...technologyHandler(dataTechnologies));
technologyHandler
следующим образом:const technologyHandler = str => str
.split(' ')
.map(n => `<p class="project_technologies-item">${n}</p>`)
.join('');
// или
const technologyHandler = str =>
str.replace(/ ?(\S+)/g, '<p class="project_technologies-item">$1</p>');
map
после её вызова:projectTechnologies.innerHTML = technologyHandler(dataTechnologies);
const digits = Object
.entries([...`${num}`].reduce((acc, n) => (acc[n] = (acc[n] || 0) + 1, acc), {}))
.reduce((acc, n) => (n[1] > 1 && acc.push(+n[0]), acc), []);
const digits = num
.toString()
.split('')
.reduce((acc, n) => (acc[n]++, acc), Array(10).fill(0))
.map((n, i) => n > 1 && i)
.filter(n => n !== false);
const digits = Array
.from(String(num), Number)
.filter((n, i, a) => i !== a.indexOf(n))
.filter((n, i, a) => i === a.indexOf(n));
const digits = (('' + num)
.match(/\d/g)
.sort()
.join('')
.match(/(\d)\1+/g) || [])
.map(n => n[0] | 0);