array.reduceRight((acc, n) => ({ ...n, children: [ ...n.children, acc ] }), { ...obj })
const isEmpty = [...inputs].some(n => !n.value);
// или
const isEmpty = !Array.prototype.every.call(inputs, n => n.value);
// или
let isEmpty = false;
for (const n of inputs) {
if (!n.value) {
isEmpty = true;
break;
}
}
// или
let isEmpty = false;
for (let i = -1; ++i < inputs.length && !(isEmpty = !inputs[i].value);) ;
// или
const isEmpty = (function isEmpty(i) {
return i < inputs.length && (!inputs[i].value || isEmpty(-~i));
})(0);
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));
const createList = arr => arr.reduceRight((acc, n) => ({ val: n, next: acc }), null);
function createList(arr) {
let list = null;
for (let i = arr.length; i--;) {
list = {
val: arr[i],
next: list,
};
}
return list;
}
button.addEventListener('click', () => {
anotherButton.click();
});
button.addEventListener('click', () => {
anotherButton.dispatchEvent(new Event('click', { bubbles: true }));
});
const filterObject = (obj, values) =>
Object.entries(obj).reduce((acc, [ k, v ]) => (
values.indexOf(v) !== -1 && (acc[k] = v),
acc
), {});
const result = filterObject(a, b);
const filterObject = (obj, filter) =>
Object.fromEntries(Object.entries(obj).filter(n => filter(...n)));
const result = filterObject(a, (k, v) => b.includes(v));
Объект FileReader позволяет веб-приложениям асинхронно читать содержимое файлов
onFileChange({ target: { files: [ file ] } }) {
if (file) {
const reader = new FileReader();
reader.addEventListener('load', e => {
this.fileinput = e.target.result;
console.log(this.fileinput);
});
reader.readAsText(file);
}
},
const flat = arr =>
(arr || []).reduce((acc, { children, ...n }) => {
if (n.isExpanded || !children) {
acc.push(n, ...flat(children));
} else {
acc.push({ ...n, children });
}
return acc;
}, []);
isExpanded: false
у кого-то из предков уровнем выше родительского, тоconst flat = arr =>
(arr || []).reduce((acc, { children, ...n }) => {
const flatChildren = flat(children);
if (n.isExpanded || !children) {
acc.push(n, ...flatChildren);
} else {
acc.push({ ...n, children: flatChildren });
}
return acc;
}, []);
если в ней нет tr столбцов
$('table').show().not(':has(tbody tr)').hide();
for (const n of document.getElementsByTagName('table')) {
n.hidden = !n.querySelector('tbody tr');
}
.hidden {
display: none;
}
document.querySelectorAll('table').forEach(function(n) {
n.classList.toggle('hidden', this(n.tBodies));
}, tBodies => Array.prototype.every.call(tBodies, n => !n.rows.length));