function createTree(data) {
const obl = {};
const org = {};
const podr = {};
data.forEach(n => {
obl[n.obl.id] = { ...n.obl, children: [] };
org[n.org.id] = { ...n.org, children: [] };
podr[n.podr.id] = { ...n.podr, children: [] };
});
data.forEach(n => podr[n.podr.id].children.push({ ...n.dolzh }));
Object.values(org).forEach(n => obl[n.parent_obl].children.push(n));
Object.values(podr).forEach(n => org[n.parent_org].children.push(n));
return Object.values(obl);
}
const tree = createTree(arr);
Array.from([...str].reduce((acc, n) => acc.set(n, -~acc.get(n)), new Map), n => n[1] + n[0])
str.split('').sort().join('').match(/(.)\1*/g).map(n => n.length + n[0])
Array.from(new Set(str), n => str.replace(RegExp(`[^${n}]`, 'g'), '').length + n)
const walk = (el, level = 0) =>
[...el.children].reduce((p, c) => {
c = walk(c, level + 1);
return p.level > c.level ? p : c;
}, { el, level });
const getLastDeepestElement = root => walk(root).el;
const getDeepestLastElement = el =>
el.lastElementChild
? getDeepestLastElement(el.lastElementChild)
: el;
// или, без рекурсии
const getDeepestLastElement = el => Array
.from(el.querySelectorAll('*'))
.pop() || el;
.on('click', function(e) {
e.stopPropagation();
const valuesShow = [ 2000, ещё какое-то значение, и ещё, и ещё, ... ];
$('#sample_form_deliv').change(function({ target: { value } }) {
$('#sample_form_pay .input-label:eq(2)').toggle(valuesShow.includes(+value));
});
Array.prototype.reduce.call(
document.querySelector('table').rows,
(acc, n) => {
if (!n.classList.contains('no')) {
acc[acc.length - 1].info.push({
subtitle: n.querySelector('th').textContent,
cell: n.querySelector('td').textContent,
});
} else if (!n.querySelector('.no2')) {
acc.push({
title: n.querySelector('.car').textContent,
info: [],
});
}
return acc;
},
[]
)
const dropzone = event.currentTarget;
dropzone.insertBefore(draggableElement, event.target.closest('tr').nextSibling);
попытался решить все через рекурсию
const createTree = (data, idKey, parentKey, parentId) =>
data.reduce((acc, n) => (parentId === n[parentKey] && acc.push({
...n,
children: createTree(data, idKey, parentKey, n[idKey]),
}), acc), []);
const tree = createTree(data, 'id', 'parentId', null);
function createTree(data, idKey, parentKey) {
const tree = Object.fromEntries(data.map(n => [ n[idKey], { ...n, children: [] } ]));
return Object
.values(tree)
.filter(n => !(tree[n[parentKey]] && tree[n[parentKey]].children.push(n)));
}
const tree = createTree(data, 'id', 'parentId');
array.reduceRight((acc, n) => ({ ...n, children: [ ...n.children, acc ] }), { ...obj })
const grouped = Object.entries(list.reduce((acc, n) => (
(acc[n.part] = acc[n.part] || []).push(n.title),
acc
), {}));
document.body.insertAdjacentHTML('beforeend', grouped
.map(([ k, v ]) => `<div>${k}</div>${v.map(n => `<div>${n}</div>`).join('')}`)
.join('')
);
document.body.append(...grouped.flat(2).map(n => {
const div = document.createElement('div');
div.innerText = n;
return div;
}));
const ids = [ 10, 13, 15 ];
.$(ids.map(n => `[data-property-id-row="${n}"]`).join(', ')).hide();
const elems = document.querySelectorAll(ids.map(n => `[data-property-id-row="${n}"]`));
for (let i = 0; i < elems.length; i++) {
elems[i].style.display = 'none';
}
document.querySelectorAll('.form-group').forEach(function(n) {
n.hidden = this.has(Number(n.getAttribute('data-property-id-row')));
}, new Set(ids));
.hidden {
display: none;
}
for (const n of document.getElementsByClassName('form-group')) {
n.classList.toggle('hidden', ids.includes(+n.dataset.propertyIdRow));
}
$("#changeCityInput").bind("keyup change",
$('#changeCityInput').on('input',
const checked = Array.from(document.querySelectorAll('.btn:checked'), n => n.value);
const filtered = arr.filter(n => checked.includes(n));