const itemSelector = '.radio';
const activeClass = 'active';
// конечно, вы можете и дальше продолжать ковырять jquery
const $items = $(itemSelector).on('change', function() {
$items.next().removeClass(activeClass);
$(this).next().addClass(activeClass);
});
// но ведь есть и другой путь
const items = document.querySelectorAll(itemSelector);
const onChange = ({ currentTarget: t }) =>
items.forEach(n => n.nextElementSibling.classList.toggle(activeClass, n === t));
items.forEach(n => n.addEventListener('change', onChange));
.radio:has(:checked) + .order__form-input {
/* сюда переносим стили, делающие input видимым */
}
arr.reduce((acc, n) => (
Object.entries(n.json_build_object).forEach(([ k, v ]) => {
(acc[k] ??= []).find(m => m.id === v.id) || acc[k].push(v);
}),
acc
), {})
links.reduce((acc, n) => {
const path = n.url.split('/');
const [ lastFolder ] = path.splice(-2);
(path.reduce((p, c) => p[c] ??= {}, acc)[lastFolder] ??= []).push(n);
return acc;
}, {})
#itemInner {
counter-reset: bullshit-counter;
}
.row {
counter-increment: bullshit-counter;
}
.row::before {
content: counter(bullshit-counter) "!!!";
}
itemInner.find('.item-num').text(i => i + 1);
const selector = '#point';
.const elem = document.querySelector(selector);
const parent = elem?.parentNode;
const elems = [...parent?.children ?? []];
const index = elems.indexOf(elem);
elems.slice(-~index || elems.length).forEach(n => parent.removeChild(n));
// или
for (
const el = document.querySelector(selector);
el?.nextElementSibling;
el.nextElementSibling.remove()
) ;
// или
document.querySelectorAll(`${selector} ~ *`).forEach(n => n.outerHTML = '');
document.querySelector('.shopWrapper').addEventListener('mouseover', function() {
const color = `#${Math.random().toString(16).slice(2, 8).padEnd(6, 0)}`;
this.style.setProperty('--random-color', color);
});
arr.map(n => {
const ids = Object
.values(n.childrenHash.reduce((acc, m) => ((acc[m.hash] ??= []).push(m.id), acc), {}))
.filter(m => m.length > 1);
return {
...n,
childrenHash: ids.length ? ids : null,
};
})
$('.container').prepend(function() {
return $('.wrapper-item h3', this);
});
document.querySelectorAll('.wrapper-item h3').forEach(n => {
n.closest('.container').prepend(n);
});
const classes = {
Class1: class {
constructor(val) {
this.val = val;
}
method1() {
console.log('Class1', this.val);
}
},
Class2: class {
constructor(val1, val2) {
this.val1 = val1;
this.val2 = val2;
}
method2() {
console.log('Class2', this.val1, this.val2);
}
},
};
function createInstanceAddCallMethod(className, constructorParams, methodName) {
const instance = new classes[className](...constructorParams);
instance[methodName]();
}
createInstanceAddCallMethod('Class1', [ 69 ], 'method1');
createInstanceAddCallMethod('Class2', [ 187, 666 ], 'method2');
const result = a.map(function(n) {
return b.slice(this[0], this[0] += n).reduce((acc, n) => acc * n, 1);
}, [ 0 ]);
const result = a.map(n => b.splice(0, n).reduce((acc, n) => acc * n, 1));
const mostFrequentNum = Array
.from(arr.reduce((acc, n) => acc.set(n, -~acc.get(n)), new Map))
.reduce((max, n) => max[1] > n[1] ? max : n, [ , 0 ])[0];
const mostFrequentNum = Object
.entries(arr.reduce((acc, n) => (acc[n] = (acc[n] ?? 0) + 1, acc), {}))
.reduce((acc, n) => (acc[n[1]] = +n[0], acc), [])
.pop();
let [0: [fruit1, fruit2, fruit3]] = arr; //Uncaught SyntaxError: Invalid destructuring assignment target
const arr = [
[ 1, 2, 3 ],
[ 5, 6, 7 ],
[ 7, 8, 9 ],
];
const [ , [ , val1 ], [ ,, val2 ] ] = arr;
console.log(val1, val2); // 6 9
const arr = [
[ 1, 2, 3 ],
[ 5, 6, 7 ],
[ 7, 8, 9 ],
];
const { 1: { 1: val1 }, 2: { 2: val2 } } = arr;
console.log(val1, val2); // 6 9
Object.values(t).forEach(n => {
n.children?.sort((a, b) => (a.order - b.order) || a.name.localeCompare(b.name));
});
Как мне изменить код, чтобы исправить ошибку?
const countries = Array.from({ length: 3 }, prompt);
new gridjs.Grid({
columns: [
'Code',
{ name: 'Flag', formatter: val => gridjs.html(`<img src="${val}">`) },
'Name',
'Capital',
'Population',
],
data: () => Promise.all(countries.map(n =>
fetch(`//restcountries.com/v3.1/name/${n}`)
.then(r => r.json())
.then(([ r ]) => [
r.altSpellings[0],
r.flags.png,
r.name.common,
r.capital[0],
r.population,
])
.catch(() => [ ,,`${n} - это не страна`,, ])
)),
}).render(document.querySelector('#wrapper'));