const idsA = new Set(ListA.map(n => n.id));
const objB = Object.fromEntries(ListB.map(({ uid, ...n }) => [ uid, (n.id = uid, n) ]));
const ListAB = ListA.map(n => ({ ...n, ...objB[n.id] }));
ListB.forEach(({ uid }) => idsA.has(uid) || ListAB.push(objB[uid]));const ListAB = [...ListB.reduce((acc, { uid: id, ...n }) => {
Object.assign(acc.set(id, acc.get(id) || { id }).get(id), n);
return acc;
}, new Map(ListA.map(n => [ n.id, {...n} ]))).values()];
$list.find('input').click(e => e.stopPropagation());if (!$(e.target).is('input')) {
$list.hide();
}
.slice(1) там, где работаете со строками таблицы. Т.е., вместо$('#data tbody tr').hide();
$('#data tbody tr').slice(0, rowsShown).show();$('#data tbody tr').slice(1).hide().slice(0, rowsShown).show();$('#data tbody tr').css('opacity',...$('#data tbody tr').slice(1).css('opacity',...
str.match(/rgb\(.*\)/).pop().match(/\d+/g)str.match(/rgb\((.*)\)/).pop().split(', ')
projectTechnologies.innerHTML = technologyHandler(dataTechnologies).map((el) => el);projectTechnologies.innerHTML = technologyHandler(dataTechnologies).map(n => n.outerHTML).join('');
// или
technologyHandler(dataTechnologies).forEach(n => projectTechnologies.appendChild(n));
// или
for (const n of technologyHandler(dataTechnologies)) {
projectTechnologies.insertAdjacentElement('beforeend', n);
}
// или
projectTechnologies.append(...technologyHandler(dataTechnologies));technologyHandler следующим образом:const technologyHandler = str => str
.split(' ')
.map(n => `<p class="project_technologies-item">${n}</p>`)
.join('');
// или
const technologyHandler = str =>
str.replace(/ ?(\S+)/g, '<p class="project_technologies-item">$1</p>');map после её вызова:projectTechnologies.innerHTML = technologyHandler(dataTechnologies);
:href="`https://oauth.vk.com/authorize?client_id=${client_id}`"computed: {
href() {
return `https://oauth.vk.com/authorize?client_id=${this.client_id}`;
},
},:href="href"methods: {
href: client_id => `https://oauth.vk.com/authorize?client_id=${client_id}`,
},:href="href(client_id)"
const digits = Object
.entries([...`${num}`].reduce((acc, n) => (acc[n] = -~acc[n], acc), {}))
.reduce((acc, n) => (~-n[1] && acc.push(+n[0]), acc), []);const digits = (function get(num, count) {
num && (count[num % 10]++, get(Math.floor(num / 10), count));
return count;
})(num, Array(10).fill(0))
.map((n, i) => n > 1 && i)
.filter(n => n !== false);const digits = Array
.from(String(num), Number)
.filter((n, i, a) => i !== a.indexOf(n))
.filter((n, i, a) => i === a.indexOf(n));const digits = (('' + num)
.match(/\d/g)
.sort()
.join('')
.match(/(\d)\1+/g) || [])
.map(n => n[0] | 0);
const values = [ 'text', 'move', 'lols' ];
const selector = values.map(n => `[data-cmd="${n}"]`).join(', ');
const elements = document.querySelectorAll(selector);const hide = el => el.style.display = 'none';
// или
const hide = el => el.style.setProperty('visibility', 'hidden');
// или
const hide = el => el.style.cssText += 'opacity: 0';
// или
const hide = el => el.setAttribute('style', 'transform: scale(0)');
// или
const hide = el => el.hidden = true;elements.forEach(hide);
// или
for (const n of elements) {
hide(n);
}
// или
for (let i = 0; i < elements.length; i++) {
hide(elements[i]);
}
// или
(function next(i, n = elements.item(i)) {
n && (hide(n), next(-~i));
})(0);
$('.count').on('input', e => $('.game_iframe').width(e.target.value));document.querySelector('.count').addEventListener('input', function() {
document.querySelector('.game_iframe').style.width = `${this.value}px`;
});
data: () => ({
values: [ 0, 14235534, 53423, -9678953, 3451, 5323467445, -123456 ],
}),
filters: {
format1: val => `${val}`.replace(/\d(?=(\d{3})+$)/g, '$& '),
},
methods: {
format2: val => val.toLocaleString('ru-RU'),
},
computed: {
formatted() {
return this.values.map(n => {
const sign = Math.sign(n) === -1;
const arr = [...String(Math.abs(n))].reverse();
return (sign ? '-' : '') + Array.from(
{ length: Math.ceil(arr.length / 3) },
(n, i) => arr.slice(i * 3, (i + 1) * 3).reverse().join('')
).reverse().join(' ');
});
},
},<div>
<div v-for="n in values">{{ n | format1 }}</div>
</div>
<div>
<div v-for="n in values">{{ format2(n) }}</div>
</div>
<pre>{{ formatted }}</pre>
мне кажется, это решение не очень хорошее из-за указания конкретного имени (phoneValues)
class App extends React.Component {
state = {
music: musicButton,
}
onClick = e => {
if (this.audio) {
this.audio.pause();
}
this.audio = new Audio(e.target.dataset.url);
this.audio.play();
}
render() {
return (
<div>
{this.state.music.map(n => (
<button onClick={this.onClick} data-url={n.url} key={n.numButton}>{n.soundsName}</button>
))}
</div>
);
}
}
v-model="answers[questionIndex]"computed: {
answerSelected() {
return this.answers[this.questionIndex].length;
},
},:disabled="!answerSelected"А можете подсказать, как в результат вывести не только отмеченные поля, но на какой вопрос были эти поля отмечены?