const $table = $('table');
const columnIndex = // здесь должен быть номер столбца с числами
const sum = $table
.find('tr:visible')
.get()
.reduce((acc, n) => acc + +$('td', n).eq(columnIndex).text(), 0);
$table
.find('th')
.eq(columnIndex)
.text(`Вес (${sum})`);
$('.news-block-2').each((i, n) => $('.text-news', n).after($('.picture-news', n)));
$('.news-block-2 tr').append(function() {
return $('.picture-news', this);
});
$('.news-block-2 .text-news').each((i, n) => $(n).parent().prepend(n));
$('.news-block-2 .picture-news').before(function() {
return $(this).next();
});
X = n => n ? (n & 1 ? '-chirp' : '') + X(n >> 1) + X(n >> 1) : ''
chirp = n => X(n).slice(1)
google.visualization.arrayToDataTable(data, true)
Array
.from(document.querySelectorAll('.obj'))
.filter(n => n.querySelector('.who')?.innerText !== 'Я')
.forEach(n => console.log(n.innerText));
const $items = $('.item');
const SLICE_SIZE = 3;
$('.container').append(i => $items.slice(i * SLICE_SIZE, (i + 1) * SLICE_SIZE));
$('label > input').change(function() {
$(this).parent().toggleClass('active', this.checked);
});
const containerSelector = '.card_options > div';
const itemSelector = '.option';
const activeClass = 'checked';
const toggleItem = item => item
?.closest(containerSelector)
.querySelectorAll(itemSelector)
.forEach(n => n.classList[n === item ? 'toggle' : 'remove'](activeClass));
// можно добавить обработчик клика каждому элементу индивидуально
document.querySelectorAll(itemSelector).forEach(function(n) {
n.addEventListener('click', this);
}, e => toggleItem(e.currentTarget));
// а можно один раз - делегированный, всей странице
document.addEventListener('click', e => {
toggleItem(e.target.closest(itemSelector));
});
const isArithmeticProgression = arr =>
arr.length > 1
? new Set(arr.map((n, i, a) => n - a[i + 1]).slice(0, -1)).size === 1
: !!arr.length;
// или
const isArithmeticProgression = arr =>
!!arr.length && arr.every((n, i, a) => !i || (n - a[i - 1] === a[1] - a[0]));
const arr = Object.values(obj);
. Дальше есть варианты:const result = arr.sort((a, b) => a.position - b.position).map(n => n.color);
const result = arr
.reduce((acc, n) => ((acc[n.position] = acc[n.position] ?? []).push(n.color), acc), [])
.flat();
const result = Object.values(Object.fromEntries(arr.map(n => [ n.position, n.color ])));
document.querySelectorAll('.row').forEach(n => n.classList.add(`row-${n.children.length}`))
const classes = {
3: 'row-3',
5: 'row-5',
7: 'row-xxx',
};
document.querySelectorAll('.row').forEach(n => {
const className = classes[n.children.length];
if (className) {
n.classList.add(className);
}
});
$('.entry__arrow--increment, .entry__arrow--decrement').click(function() {
const $this = $(this);
$this.closest('.entry__box').find('.entry__data').text(function(i, text) {
const { step, max, min } = this.dataset;
let newVal = +text + step * ($this.hasClass('entry__arrow--increment') ? 1 : -1);
if (newVal > max) {
newVal = min;
} else if (newVal < min) {
newVal = max;
}
return `${newVal}`.padStart(2, 0);
});
});