const arr = Object
.entries(obj)
.reduce((acc, [ k, values ]) => (
values.forEach((v, i) => (acc[i] ??= {})[k] = v),
acc
), []);
const keys = Object.keys(obj);
const arr = obj[keys[0]]?.map((_, i) => {
return Object.fromEntries(keys.map(k => [ k, obj[k][i] ]));
}) ?? [];
const duplicates = arr.filter((n, i, a) => a.filter(m => m[0] === n[0]).length > 1);
const duplicates = Object
.values(arr.reduce((acc, n) => ((acc[n[0]] ??= []).push(n), acc), {}))
.flatMap(n => n.length > 1 ? n : []);
const duplicates = Array
.from(arr
.reduce((acc, n) => (acc.get(n[0]).push(n), acc), new Map(arr.map(n => [ n[0], [] ])))
.values())
.reduce((acc, n) => (n.length > 1 && acc.push(...n), acc), []);
const duplicates = arr.filter(function(n) {
return this.get(n[0]);
}, arr.reduce((acc, [ n ]) => acc.set(n, acc.has(n)), new Map));
document.querySelector('.btn--start').addEventListener('click', filterItems);
document.querySelector('select').addEventListener('change', e => e.target.value === 'all' && filterItems());
function filterItems() {
const val = document.querySelector('select').value;
document.querySelectorAll('.item').forEach(n => {
n.style.display = [ n.dataset.elem, 'all' ].includes(val)
? 'block'
: 'none';
});
}
Object.fromEntries(new URLSearchParams(arr.join('&')))
arr.reduce((acc, n) => (
n = n.split('='),
acc[n[0]] = n[1],
acc
), {})
Object.assign(...arr.map(n => n.match(/[^=]+/g)).map(([ k, v ]) => ({ [k]: v })))
eval(`({${arr.map(n => `"${n.replace('=', '":"')}"`)}})`)
<div data-value="69"></div>
<div data-value="187"></div>
<div data-value="666"></div>
function animateValue(elem) {
return new Promise(resolve => {
const endValue = +elem.dataset.value;
let currValue = 0;
const interval = setInterval(() => {
if (++currValue === endValue) {
clearInterval(interval);
resolve();
}
elem.innerText = currValue;
}, 20);
});
}
Array
.from(document.querySelectorAll('[data-value]'))
.reduce((p, c) => p.then(() => animateValue(c)), Promise.resolve());
The useRef() Hook isn’t just for DOM refs. The “ref” object is a generic container whose current property is mutable and can hold any value, similar to an instance property on a class.
justify-content
распределяет содержимое блока вдоль главной оси, в качестве которой у вас установлена вертикальная (flex-direction: column
).align-items
. const result = arr.reduce((acc, n, i) => (
(i & 1) || acc.push(0),
acc[~-acc.length] += n,
acc
), []);
function chunked(data, chunkSize) {
return Array.prototype.reduce.call(
data,
(acc, n, i) => ((acc[i / chunkSize | 0] ??= []).push(n), acc),
[]
);
}
function sum(data, val = n => n) {
const getVal = val instanceof Function ? val : n => n[val];
return Array.prototype.reduce.call(
data,
(acc, n) => acc + getVal(n),
0
);
}
const result = chunked(arr, 2).map(n => sum(n));
isOpen
с помощью директивы v-model
, замените :is-open="item.isOpen"
на v-model:is-open="item.isOpen"
.isOpen = !isOpen
на $emit('update:isOpen', !isOpen)
. .active {
&::after {
content: "hello, world!!";
}
}
<a class="tabs-select__button" data-text="hello, world!!">
<a class="tabs-select__button" data-text="fuck the world">
.active {
&::after {
content: attr(data-text);
}
}
const flatArr = arr.flatMap(n => Array.isArray(n.DOP) ? n.DOP : []);
// или
const flatArr = Array.prototype.concat.apply([], arr.map(n => n.DOP ?? []));
// или
const flatArr = arr.reduce((acc, n) => (n.DOP && acc.push(...n.DOP), acc), []);
const unique = Object.values(Object.fromEntries(flatArr.map(n => [ n.NAME, n ])));
// или
const unique = flatArr.filter(function({ NAME: n }) {
return !(this[n] = this.hasOwnProperty(n));
}, {});
// или
const unique = flatArr.filter((n, i, a) => n === a.find(m => m.NAME === n.NAME));
function formatDate(str) {
const d = new Date(str.replace('_', ' 1, '));
d.setMonth(d.getMonth() - 1);
return d.toLocaleDateString('en-US', {
month: 'short',
year: 'numeric',
}).replace(' ', '_');
}
formatDate('Feb_2021') // "Jan_2021"
formatDate('Jan_2000') // "Dec_1999"
this.setState(({ items }) => ({
items: items.map((n, i) => ({ ...n, id: i })),
}));
state = {
items: this.props.items.map((n, i) => ({ ...n, id: i })),
}
g
на самом деле отсутствует. Смотрите внимательнее, куда вы его попытались вписать. computed: {
grouped() {
return this.arr.reduce((acc, n) => ((acc[n.group] ??= []).push(n), acc), {});
},
},
<v-expansion-panels>
<v-expansion-panel v-for="(items, groupName) in grouped">
<v-expansion-panel-header>{{ groupName }}</v-expansion-panel-header>
<v-expansion-panel-content>
<div v-for="n in items">{{ n.name }}</div>
</v-expansion-panel-content>
</v-expansion-panel>
</v-expansion-panels>
str.match(/(?<=\. ).+(?= \(%\))/)[0]
// или
str.replace(/^.*?\. | \(%\).*$/g, '')
// или
str.split('. ').pop().split(' (%)').shift()
string value
long index = value[l];
'1'
('2'
, '3'
, ...) будет неявно преобразовано в 1
(2
, 3
, ...). Зря. Так не будет. Вы получите код соответствующего символа. Ваше счастье, коды цифровых символов расположены один за другим, в порядке возрастания соответствующих им цифр, так что достаточно вычесть код нуля, чтобы получить нужное число:long index = value[l] - '0';