app.ifScroll =ifScroll.value =.
const containers = document.querySelectorAll('.parent');
const tag = 'div';
const className = 'child';containers.forEach((n, i) => {
n.insertAdjacentHTML(
'beforeend',
`<${tag} class="${className}">${arr[i]}</${tag}>`
);
});
// или
for (const [ i, n ] of containers.entries()) {
n.append(Object.assign(document.createElement(tag), {
className,
innerText: arr[i],
}));
}
// или
for (let i = 0; i < containers.length; i++) {
const el = document.createElement(tag);
el.classList.add(className);
el.textContent = arr[i];
containers[i].insertAdjacentElement('beforeend', el);
}
// или
(function add(i, n = containers.item(i)) {
if (n) {
n.appendChild(document.createElement(tag));
n.lastChild.setAttribute('class', className);
n.lastChild.insertBefore(new Text(arr[i]), null);
add(-~i);
}
})(0);
const [ checked, setChecked ] = React.useState(false);<input
type="checkbox"
checked={checked}
onChange={e => setChecked(e.target.checked)}
...<button
disabled={!checked}
...
нет примера их использования
<q-select
ref="select"
...<q-btn
@click="$refs.select.showPopup()"
...
const createArr = length =>
Array.from({ length }, (_, i) =>
Array.from({ length }, (_, j) =>
(i === j || i === length - j - 1) +
((i <= j && i <= length - j - 1) || (i >= j && i >= length - j - 1))
)
);
const newArr = arr.reduce((acc, n) => (
acc.push({ ...n, fractionTotal: n.fraction + (acc.at(-1)?.fractionTotal ?? 0) }),
acc
), []);
// или
const newArr = arr.map(function({ ...n }) {
n.fractionTotal = this[0] += n.fraction;
return n;
}, [ 0 ]);arr.forEach((n, i, a) => n.fractionTotal = n.fraction + (i && a[i - 1].fractionTotal));
// или
arr.reduce((acc, n) => n.fractionTotal = acc + n.fraction, 0);
const createTable = (
rows,
cols,
cell,
{
rowSeparator = '\n',
colSeparator = '',
} = {},
) =>
Array.from({ length: rows }, (_, i) =>
Array.from({ length: cols }, (_, j) =>
cell(i, j)
).join(colSeparator)
).join(rowSeparator);console.log(createTable(8, 8, (i, j) => (i ^ j) & 1));
document.body.innerHTML = createTable(
30,
50,
(i, j) => (i + j) % 2,
{ rowSeparator: '<br>' }
);
const sorted = (data, keys) => Array
.from(data, n => [ n ].concat(keys(n)))
.sort((a, b) => {
let diff = 0;
for (let i = 0; ++i < a.length && !(diff = ((a[i] < b[i]) ? -1 : +(a[i] > b[i])));) ;
return diff;
})
.map(n => n[0]);const sortChildren = (el, keys) =>
el.append(...sorted(el.children, keys));const ul = document.querySelector('ul');
ul.addEventListener('change', e => sortChildren(
e.currentTarget,
el => [
-el.querySelector('input').checked,
el.innerText.trim().toLowerCase(),
]
));
ul.dispatchEvent(new Event('change'));
class Solution:
def rotate(self, matrix: List[List[int]]) -> None:
length = len(matrix)
for i in range(0, length // 2):
for j in range(i, length - i - 1):
matrix[i][j], \
matrix[j][length - i - 1], \
matrix[length - i - 1][length - j - 1], \
matrix[length - j - 1][i] \
= \
matrix[length - j - 1][i], \
matrix[i][j], \
matrix[j][length - i - 1], \
matrix[length - i - 1][length - j - 1]
arr.filter(RegExp.prototype.test.bind(/^[рим]*$/i))
// или
arr.filter(n => !n.match(/[^рим]/i))
// или
arr.filter(n => !n.replace(/р|и|м/gi, ''))
// или
arr.filter(n => [...n.toLowerCase()].every(m => 'рим'.includes(m)))
const result = Object.values(data.reduce((acc, n) => (
(acc[n.brand] ??= { ...n, price: 0 }).price += n.price,
acc
), {}));function uniqueWithSum(data, key, sumKey) {
const getKey = key instanceof Function ? key : n => n[key];
const unique = new Map;
for (const n of data) {
const k = getKey(n);
unique
.set(k, unique.get(k) ?? (u => (u[sumKey] = 0, u))(structuredClone(n)))
.get(k)[sumKey] += n[sumKey];
}
return [...unique.values()];
}// ваш случай
const result = uniqueWithSum(data, n => n.brand, 'price');
// элементам исходного массива не обязательно быть объектами
uniqueWithSum([
[ 'aaa', 1 ],
[ 'aaa', 10 ],
[ 'aaa', 100 ],
[ 'bbb', 666 ],
], 0, 1) // [ [ 'aaa', 111 ], [ 'bbb', 666 ] ]
ul в transition следует завернуть li в transition-group:<transition-group tag="ul" name="fade" class="buttons">
<li
v-if="какое здесь будет условие, предлагаю подумать самостоятельно"
...
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;
}, {})links.reduce((acc, n) => (
n.url
.match(/[^\/]+(?=\/)/g)
.reduce((p, c, i, a) => p[c] ??= (-~i < a.length ? {} : []), acc)
.push(n),
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);