const [ arr1, arr2 ] = arr.list
.map(n => [ n, +n.pos.dv.slice(1) ])
.sort((a, b) => a[1] - b[1])
.reduce((acc, n) => (acc[+(n[1] >= 38)].push(n[0]), acc), [ [], [] ])
.map(n => ({ list: n }));
.red {
background: red;
}$('.table').on('change', function(e) {
const $tr = $(e.target).closest('tr');
const ajaxdata = $tr.find('.ajaxdata').val();
const subcat = $tr.find('.subcat').val();
$tr.toggleClass('red', ajaxdata === 'none' && subcat === 'none');
}).find('tr').change();
// или
const table = document.querySelector('table');
table.addEventListener('change', e => {
const tr = e.target.closest('tr');
const ajaxdata = tr.querySelector('.ajaxdata').value;
const subcat = tr.querySelector('.subcat').value;
tr.classList.toggle('red', ajaxdata === 'none' && subcat === 'none');
})
table.querySelectorAll('tr').forEach(n => {
n.dispatchEvent(new Event('change', { bubbles: true }));
});
item.isShow = false;this.$set(item, 'isShow', false);data() {
return {
apiCopy: this.api.map(n => ({
...n,
requests: n.requests.map(m => ({
...m,
isShow: false,
})),
})),
};
},
const mustStay = arr => arr.every(n => n.value !== '-');const newArr = arr.filter(mustStay);
// или
const newArr = [];
for (const n of arr) {
if (mustStay(n)) {
newArr.push(n);
}
}
// или
const newArr = [];
for (let i = 0; i < arr.length; i++) {
if (mustStay(arr[i])) {
newArr[newArr.length] = arr[i];
}
}
// или
const newArr = (function get(i, n = arr[i]) {
return n
? [ mustStay(n) ? [ n ] : [], get(i + 1) ].flat()
: [];
})(0)for (let i = 0; i < arr.length; i++) {
if (!mustStay(arr[i])) {
for (let j = i--; ++j < arr.length; arr[j - 1] = arr[j]) ;
arr.pop();
}
}
// или
arr.reduceRight((_, n, i, a) => mustStay(n) || a.splice(i, 1), null);
// или
arr.splice(0, arr.length, ...arr.filter(mustStay));
// или
arr.length -= arr.reduce((acc, n, i, a) => (
a[i - acc] = n,
acc + !mustStay(n)
), 0);
const length = Math.max(...arr.map(n => n.length));
// или
const length = arr.reduce((max, { length: n }) => max > n ? max : n, 0);for (const n of arr) {
const id = 1 + Math.max(0, ...n.map(m => m.id));
n.push(...Array.from(
{ length: length - n.length },
(_, i) => ({ id: id + i, value: '_' })
));
}const newArr = arr.map(n => Array.from({ length }, (_, i) => ({
id: i + 1,
value: i < n.length ? n[i].value : '-',
})));
[ 7, 7, 7, 0, 1, 1 ]? В первом случае 2 - повторяются семёрка и единица, во втором 5 - три семёрки плюс две единицы.const duplicateCount = Object
.values(arr.reduce((acc, n) => (acc[n] = (acc[n] || 0) + 1, acc), {}))
.filter(n => n > 1)
.length;
// или
const duplicateCount = Array
.from(arr.reduce((acc, n) => acc.set(n, acc.has(n)), new Map).values())
.reduce((acc, n) => acc + n, 0);
// или
const duplicateCount = new Set(arr.filter((n, i, a) => i !== a.indexOf(n))).size;const duplicateCount = Object
.values(arr.reduce((acc, n) => (acc[n] = acc.hasOwnProperty(n), acc), {}))
.reduce((acc, n) => acc - !n, arr.length);
// или
const duplicateCount = Array
.from(arr.reduce((acc, n) => acc.set(n, -~acc.get(n)), new Map).values())
.reduce((acc, n) => acc + (n > 1) * n, 0);
// или
const duplicateCount = arr
.filter((n, i, a) => a.indexOf(n) !== a.lastIndexOf(n))
.length;
const isArrOK = arr => arr.length && arr.every(n => n.value !== '-');const newArr = arr.reduce((acc, { arr: n }) => (
isArrOK(n) && acc.push(n),
acc
), []);
// или
const newArr = arr.map(n => n.arr).filter(isArrOK);
// или
const newArr = [];
for (const n of arr) {
if (isArrOK(n.arr)) {
newArr[newArr.length] = n.arr;
}
}
$('#file').on('change', ({ target: { files: [ file ] } }) => {
$('#info-file').html([ 'name', 'size', 'type' ]
.map(n => `<div>${n}: ${file[n]}</div>`)
.join('')
);
});
<div class="nav">
<div class="nav-inner"></div>
</div>.nav {
height: 20px;
background: #ddd;
}
.nav-inner {
height: 100%;
background: red;
transition: width 0.5s;
}const updateNav = slide => $navInner.width(`${(slide + 1) / slidesCount * 100}%`);$slick.on({
init: (e, slick) => updateNav(slick.currentSlide),
beforeChange: (e, slick, currSlide, nextSlide) => updateNav(nextSlide),
})$nav.on('click', function(e) {
$slick.slick('slickGoTo', e.offsetX / $nav.width() * slidesCount | 0);
});как сделать так, чтобы width полосы высчитывался в зависимости от slidesToShow
slidesCount надо заменить на slidesCount - slidesToShow + 1.
Насколько хороши варианты:
1. интервалом синхронить стейт корзины.
2. Синхронить стейт при событии onunload
3. Писать обработчик кликов, который будет регулировать частоту запросов (очень не хочется)
methods: {
syncCart: debounce(function() {
...
}),
},
watch: {
'$store.state.cart': {
immediate: true,
deep: true,
handler: 'syncCart',
},
},
$("#box1:checked, #box2:checked").val()$('#logistic input:checked').get().reduce((acc, n) => acc + +n.value, 0)
function GetCookies(name) { <...> return null; } <...> faves.push(fav); <...> var myfaves = JSON.parse(GetCookies('favespages')); faves = myfaves;
faves = myfaves instanceof Array ? myfaves : [];.
data: () => ({
items: [
{ раз_свойство: '', два_свойство: '', три_свойство: '', ... },
...
],
}),<table>
<tbody>
<tr v-for="(n, i) in items">
<td>#{{ i + 1 }}</td>
<td v-for="(v, k) in n">
{{ k }}:
<input v-model="n[k]">
</td>
</tr>
</tbody>
</table>
const result = tags.filter(n => active.some(m => m.name === n.name));function intersection(data1, data2, key = n => n) {
const result = [];
const getKey = key instanceof Function ? key : n => n[key];
const keys = new Set(Array.from(data2, getKey));
for (const n of data1) {
if (keys.has(getKey(n))) {
result.push(n);
}
}
return result;
}// ваш случай
const result = intersection(tags, active, 'name');
// есть и другие варианты применения
intersection([ 69, 187, 666 ], [ 0, 1, 2, 3, 187 ]) // [187]
intersection(Array(10).keys(), Array(3).keys()) // [0, 1, 2]
intersection('aBCdE', 'bDfHj', n => n.toLowerCase()) // ['B', 'd']