computed: {
catId() {
return this.$route.meta.catId;
},
},
<ListProducts :catId="$route.meta.catId" />
@click="checkOption(option);"
v-model
is required
domProps: {
value: this.value,
},
const className = 'класс элементов, чьи id вам надо получить';
const elems = document.querySelectorAll(`.${className}`);
// или
const elems = document.getElementsByClassName(className);
const getId = el => el.id;
// или
const getId = el => el.getAttribute('id');
// или
const getId = el => el.attributes.id.value;
const ids = Array.from(elems, getId);
// или
const ids = Array.prototype.map.call(elems, getId);
// или
const ids = [];
for (const n of elems) {
ids.push(getId(n));
}
// или
const ids = [];
for (let i = 0; i < elems.length; i++) {
ids[i] = getId(elems[i]);
}
v-model="selectField[index]"
заменяете на v-model="item.value"
, например, а selectField.includes(name)
на conditionList.some(n => n.value === name)
. бибилиотека react-yandex-maps не имеет такой функциональности
const result = Object.values(arr.reduce((acc, n) => (
acc[n.id] = n.checked ? n : (acc[n.id] || n),
acc
), {}));
const result = arr.reduce((acc, n) => {
const i = acc.findIndex(m => m.id === n.id);
if (!~i || (!acc[i].checked && n.checked)) {
acc.push(n);
if (~i) {
acc.splice(i, 1);
}
}
return acc;
}, []);
// или
const result = Object
.values(arr.reduce((acc, n, i) => (
(!acc[n.id] || (!acc[n.id][0].checked && n.checked)) && (acc[n.id] = [ n, i ]),
acc
), {}))
.sort((a, b) => a[1] - b[1])
.map(n => n[0]);
[...document.querySelectorAll('.buy > i')]
.filter((n, i, a) => i !== a.findIndex(m => m.innerText === n.innerText))
.forEach(n => n.parentNode.style.display = 'none');
const grouped = Array
.from(document.querySelectorAll('.buy > i'), n => [ n.parentNode, n.innerText ])
.reduce((acc, n) => ((acc[n[1]] = acc[n[1]] || []).push(n[0]), acc), {});
Object.values(grouped).forEach(n => n.forEach((m, i) => m.hidden = !!i));
.hidden {
display: none;
}
const unique = new Set();
for (const n of document.querySelectorAll('.buy > i')) {
if (unique.has(n.innerText)) {
n.parentNode.classList.add('hidden');
} else {
unique.add(n.innerText);
}
}
people.filter((n, i, a) => n.country && i === a.findIndex(m => m.country === n.country))
people.filter((n, i, a) => n.country && n === a.find(m => m.country === n.country))
people.filter(function({ country: n }) {
return n && !(this[n] = this.hasOwnProperty(n));
}, {})
Object.values(people.reduce((acc, n) => (n.country && (acc[n.country] = n), acc), {}))
[...people.reduce((acc, n) => n.country ? acc.set(n.country, n) : acc, new Map).values()]
Array.from(
new Set(people.map(n => n.country).filter(Boolean)),
n => people.find(m => m.country === n)
)
const block = document.querySelector('.block');
const inputSelector = 'input[type="number"]';
const toggleBlock = () =>
block.style.display = Array
.from(document.querySelectorAll(inputSelector))
.some(n => n.value && +n.value > +n.min)
? 'block'
: 'none';
document.addEventListener('input', e => e.target.matches(inputSelector) && toggleBlock());
toggleBlock();
// или
const inputs = document.querySelectorAll(inputSelector);
const toggleBlock = () =>
block.hidden = Array.prototype.every.call(
inputs,
n => !n.value || +n.value <= +n.min
);
inputs.forEach(n => n.addEventListener('input', toggleBlock));
toggleBlock();
if ( typeof arr[i] === 'number' ) { x*= arr[i];
arr[i + 1]
окажется строкой? Сначала надо проверить всё, а уже потом вычислять (если потребуется) объединённое значение:function bullshit(arr) {
if (arr.every(n => typeof n === 'number')) {
return arr.reduce((acc, n) => acc * n, 1);
}
if (arr.every(n => typeof n === 'string')) {
return arr.join('');
}
return null;
}
bullshit([ 1, 2, 3 ]) // 6
bullshit([ 'a', 'b', 'c' ]) // 'abc'
bullshit([ 1, '!' ]) // null
function bullshit(arr) {
const count = arr.reduce((acc, n) => {
const type = typeof n;
acc[type] = (acc[type] || 0) + 1;
return acc;
}, {});
switch (arr.length) {
case count.number: return arr.reduce((acc, n) => acc * n, 1);
case count.string: return arr.join('');
default: return null;
}
}
Object.fromEntries(Object
.entries(obj)
.sort((a, b) => a[0] - b[0])
.reduce((acc, [ k, v ], i, a) => (
i && k - a[~-i][0] === 1 || acc.push([ k, 0 ]),
acc[~-acc.length][1] += v,
acc
), [])
)
return { actionList };
$('.wrap').on('input', function(e) {
const valid = $(this).find('.valid').get().map(el => {
if (el === e.target) {
$(el).toggleClass('empty', !el.value);
}
return el.value;
}).every(Boolean);
$('.btn')
.toggleClass('btn--isvalid', valid)
.toggleClass('btn--novalid', !valid);
});