Object.values(arr.reduce((acc, n) => {
const date = n.date.split(' ', 1)[0];
(acc[0][date] = acc[0][date] || { id: ++acc[1], date, docs: [] }).docs.push(n);
return acc;
}, [ {}, 0 ])[0])
[...arr.reduce((acc, n) => {
const [ date ] = n.date.match(/\S+/);
acc.set(date, acc.get(date) || { id: -~acc.size, date, docs: [] }).get(date).docs.push(n);
return acc;
}, new Map).values()]
let show = 1;
function sh() {
const [ display, text ] = [ [ 'none', 'Развернуть' ], [ 'block', 'Свернуть' ] ][show ^= 1];
[...document.querySelectorAll('.list-row')].slice(3).forEach(n => n.style.display = display);
document.querySelector('#button').textContent = text;
}
window.addEventListener('load', sh);
function walk(node) {
if (node) {
console.log(node);
walk(node.next);
}
}
function walk(node) {
while (node) {
console.log(node);
node = node.next;
}
}
.tags li.hidden {
display: none;
}
document.querySelectorAll('.tags b').forEach(n => {
n.closest('li').classList.add('xxx');
n.addEventListener('click', onClick);
});
function onClick(e) {
for (
let el = e.target.closest('li');
(el = el.nextElementSibling) && !el.classList.contains('xxx');
el.classList.toggle('hidden')
) ;
}
.active {
height: 300px;
cursor: pointer;
background-color: green;
overflow: auto;
}
$('.qwerty').on('click', function() {
$(this).toggleClass('active');
});
document.addEventListener('click', function(e) {
const t = e.target;
if (t.matches('button.apply-button') && t.closest('blabla')) {
// ...
}
});
const colors = [
'red', 'blue', 'magenta', 'green', 'yellow',
'aqua', 'brown', 'silver', 'lime'
];
for (let i = colors.length; --i > 0;) {
const j = Math.random() * (i + 1) | 0;
[ colors[i], colors[j] ] = [ colors[j], colors[i] ];
}
document.querySelectorAll('.item').forEach((n, i) => {
n.style.backgroundColor = colors[i];
});
Object.assign(users.find(n => n.id === id), user);
const u = users.find(n => n.id === id);
if (u) {
Object.assign(u, user);
} else {
// добавляем, например
users.push({ ...user, id });
}
class Element {
constructor(el) {
this.el = el;
this.button = this.el.querySelector('[data-element-ref="button"]');
this.template = this.el.querySelector('[data-element-ref="template"]');
this.button.addEventListener('click', this.onClickPrimaryButton);
this.template.addEventListener('click', this.onClickButtonElement);
}
onClickPrimaryButton = () => {
this.template.innerHTML += template;
}
onClickButtonElement = (e) => {
if (e.target.dataset.elementRef === 'template-button') {
console.log(e.target);
}
}
}
const usersList = users.map(n => `${n.firstName} ${n.lastName} ${n.email}`);
const usersList = users.map(function(n) {
return this.map(k => n[k]).join(' ');
}, [ 'firstName', 'lastName', 'email' ]);
const containerSelector = '.container';
const buttonSelector = 'button';
const activeContainerClass = 'btn-active';
const activeButtonClass = 'active';
$(document).on('click', buttonSelector, function(e) {
const $button = $(this).toggleClass(activeButtonClass);
$button
.closest(containerSelector)
.toggleClass(activeContainerClass, $button.hasClass(activeButtonClass))
.find(buttonSelector)
.not($button)
.removeClass(activeButtonClass);
});
document.addEventListener('click', e => {
const button = e.target.closest(buttonSelector);
if (button) {
const container = button.closest(containerSelector);
container.querySelectorAll(buttonSelector).forEach(n => {
n.classList[n === button ? 'toggle' : 'remove'](activeButtonClass);
});
container.classList.toggle(
activeContainerClass,
button.classList.contains(activeButtonClass)
);
}
});
$('#btn__AddEmployee').click(function() {
const checked = $(this).prev().prop('checked');
$('#table__Employee tbody').append(`
<tr>
<td>
<input type="checkbox" ${checked ? 'checked="checked"' : ''}>
</td>
</tr>
`);
});
document.querySelector('#btn__AddEmployee').addEventListener('click', e => {
const input = document.createElement('input');
input.type = 'checkbox';
input.checked = e.target.previousElementSibling.checked;
document
.querySelector('#table__Employee tbody')
.insertRow()
.insertCell()
.append(input);
});
const count = matrix.flat().reduce((acc, n) => (acc[n] = -~acc[n], acc), {});
const count = {};
for (const row of matrix) {
for (const n of row) {
if (!count.hasOwnProperty(n)) {
count[n] = 0;
}
count[n]++;
}
}