return character === '...' ? '...' : character;
const replacements = {
'...': '...',
'...': '...',
...
};
const newCharacters = characters.map(n => replacements[n] || n);
arr.flatMap(n => n.split(', ').map(Number))
`${arr}`.split(/\D+/).map(n => +n)
String(arr).match(/\d+/g).map(n => parseInt(n))
eval('[' + arr + ']')
JSON.parse('['.concat(arr, ']'))
$('.box-none', this).slideToggle(300);
$(this).find('.box-none').slideToggle(300);
document.querySelector('.copybox').addEventListener('click', ({ target: t }) => {
if (t.tagName === 'BUTTON') {
navigator.clipboard.writeText(t.previousElementSibling.textContent);
}
});
const groupedAndUnique = Object.entries(arr.reduce((acc, n) => {
(acc[n.category] = acc[n.category] ?? new Set).add(n.type);
return acc;
}, {}));
document.body.insertAdjacentHTML('beforeend', `
<ul>${groupedAndUnique.map(([ k, v ]) => `
<li>
${k}
<ul>${Array.from(v, n => `
<li>${n}</li>`).join('')}
</ul>
</li>`).join('')}
</ul>`
);
const ul = document.createElement('ul');
ul.append(...groupedAndUnique.map(([ header, items ]) => {
const li = document.createElement('li');
li.append(header, document.createElement('ul'));
for (const n of items) {
li.lastChild.append(document.createElement('li'));
li.lastChild.lastChild.textContent = n;
}
return li;
}));
document.body.append(ul);
$('.chosen-select')
.find(`option[data-value="${category}"]`)
.prop('selected', true)
.end()
.trigger('chosen:updated');
$owl.on('mouseenter mouseleave', function(e) {
$(this).data('owl.carousel').options.autoplay = e.type === 'mouseenter';
$(this).trigger('refresh.owl.carousel');
});
$owl.on('mouseenter mouseleave', function(e) {
$(this).trigger(({
mouseenter: 'play',
mouseleave: 'stop',
})[e.type] + '.owl.autoplay');
});
Uncaught TypeError: number[i].parents is not a function
number[i]
должно было быть $(number[i])
или number.eq(i)
. Но вообще, организовывать цикл вручную нет необходимости:$('.person-wr a.desc')
.filter((i, n) => !n.innerText.trim())
.closest('.add-info')
.hide();
document.addEventListener('click', e => {
const item = e.target.closest('.preliminary-item');
if (item) {
[ 'name', 'quantity', 'proximity' ].forEach(n => {
const html = `<p>${item.querySelector(`.request-${n}`).textContent}</p>`;
document.querySelector(`.result-${n}`).insertAdjacentHTML('beforeend', html);
});
}
});
$(document).on('click', '.preliminary-item', function() {
$.each([ 'name', 'quantity', 'proximity' ], (i, n) => {
$(`.result-${n}`).append(`<p>${$(`.request-${n}`, this).text()}</p>`);
});
});
case 'TURN_DONE_POST':
return {
...state,
data: state.data.map(n => n.id === action.payload
? { ...n, done: !n.done }
: n
),
};
phonesProcessed() {
const classes = Object.fromEntries(this.classes.map(({ classinfoName: c, items }) => [
c,
Object.fromEntries(items.map(n => [
n[`id${c[0].toUpperCase()}${c.slice(1)}`],
n.name,
])),
]));
return this.phones.map(n =>
Object.fromEntries(Object.entries(n).map(([ k, v ]) => [
k,
classes.hasOwnProperty(k) ? classes[k][v] : v,
]))
);
},
created() {
[
[ '5ad979f4-7393-11ea-b9b1-d7fe1923484d', 'classinfo', 'classes' ],
[ '46bf408d-739d-11ea-b9b1-5301e3b2b9ba', 'phones', 'phones' ],
].forEach(([ key, apiPropName, componentPropName ]) => {
axios
.get(`https://jsonblob.com/api/${key}`)
.then(({ data: { [apiPropName]: d } }) => this[componentPropName] = d)
.catch(e => this.errors.push(e));
});
},
computed: {
groupedItems() {
const { items } = this;
const statuses = [...new Set(items.map(n => n.status))];
const positions = [...new Set(items.map(n => n.position))];
return items.reduce(
(acc, n) => (acc[n.status][n.position].push(n), acc),
Object.fromEntries(statuses.map(status => [
status,
Object.fromEntries(positions.map(position => [
position,
[]
]))
]))
);
},
},
<ul>
<li v-for="(statusGroup, status) in groupedItems">
<h2>{{ status }}</h2>
<ul>
<li v-for="(positionGroup, position) in statusGroup">
<h3>{{ position }}</h3>
<ul>
<li v-for="n in positionGroup">{{ n.name }}</li>
</ul>
</li>
</ul>
</li>
</ul>
name: 'v-tree',
props: [ 'items' ],
<ul v-if="items instanceof Object">
<li v-for="n in items">
<b>{{ n.name }}</b>
<v-tree :items="n.children" />
</li>
</ul>
const group = (arr, keys) =>
arr.reduce((acc, n) => {
keys.reduce((g, k, i, a) => {
const name = n[k];
return (g[name] = g[name] || {
name,
children: i === a.length - 1 ? [] : {},
}).children;
}, acc).push(n);
return acc;
}, keys.length ? {} : []);
computed: {
groupedItems() {
return group(this.items, [ 'status', 'position' ]);
},
},
<v-tree :items="groupedItems" />