const tableId = 'news';
const trSelector = 'tbody tr';$(`#${tableId}`).show().not(`:has(${trSelector})`).hide();
// или
const $table = $('[id="' + tableId + '"]');
$table.toggle(!!$table.find(trSelector).length);(t => t.hidden = !t.querySelector(trSelector))
(document.querySelector('#'.concat(tableId)));
// или (в стили надо будет добавить .hidden { display: none; })
const table = document.getElementById(tableId);
table.classList.toggle('hidden', Array.prototype.every.call(
table.tBodies,
n => !n.rows.length
));#news:not(:has(tbody tr)) {
display: none;
}
infinite: false в настройках слайдера.$slick.on('beforeChange', function(e, slick, currentSlide, nextSlide) {
$(this).find('.slick-next').prop('disabled', nextSlide === slick.slideCount - 1);
});а как ей стиль менять?
slick-disabled, можете с его помощью переопределять их внешний вид.
const attacks = [
{ minChance: 7, damage: 40, name: 'critical' },
{ minChance: 5, damage: 20, name: 'big' },
{ minChance: 0, damage: 10, name: 'weak' },
];
const messages = {
start: (player, enemy) => `Welcome! Yor health is - ${player}%, your enemy health - ${enemy}%`,
end: (player, enemy) => `You ${enemy <= 0 ? 'win' : 'lost'}! Your hp level - ${player}, opponents hp level - ${enemy}`,
chance: (player, enemy) => `your chance - ${player}, your opponent chance - ${enemy}`,
turn: (player, enemy, hit, isEnemy) =>
`${isEnemy ? 'Enemy' : 'Your'} turn...
${isEnemy ? 'Enemy' : 'You'} did a ${hit} hit
${isEnemy ? 'Your' : 'Enemy'} hp - ${isEnemy ? player : enemy}`,
};
const simpleFight = () => {
const hp = [ 100, 100 ];
console.log(messages.start(...hp));
while (hp.every(n => n > 0)) {
const chances = hp.map(() => Math.random() * 11 | 0);
console.log(messages.chance(...chances));
if (chances[0] !== chances[1]) {
const chance = Math.max(...chances);
const attack = attacks.find(n => n.minChance < chance);
const isEnemyAttacks = chance === chances[1];
hp[+!isEnemyAttacks] -= attack.damage;
console.log(messages.turn(...hp, attack.name, isEnemyAttacks));
}
}
console.log(messages.end(...hp));
};
const sum = str.match(/\d+/g).reduce((acc, n) => acc + +n, 0);
// или
let sum = 0;
for (const n of str.split(/\D+/)) {
sum += Number(n);
}
// или
const sum = eval(str.replace(/\|(\d+)\|/g, '+$1'));preg_match_all('/\d+/', $str, $matches);
$sum = array_sum($matches[0]);
// или
$sum = 0;
foreach (preg_split('/\D+/', $str) as $n) {
$sum += intval($n);
}
// или
eval('$sum = '.preg_replace('/\|(\d+)\|/', '+$1', $str).';');
id="mse2_ms|price_0"| засунуть в id.#, а как значение атрибута, т.е. [id="mse2_ms|price_0"].
после перезагрузки страницы получаю undefined
правильно ли я возвращаю копию значения с объекта store.singleMetricNamesMap
$store.state.singleMetricNamesMap[value.metricId]. Если так по-вашему слишком длинно - сделайте в компоненте вычисляемое свойство, которое будет представлять singleMetricNamesMap.
width: 100% !important;, а родительский элемент canvas'а карты имеет нулевые размеры.new ymaps.Map("map", {
data: () => ({
size: 52,
col: 0,
row: 0,
}),
methods: {
onMouseMove(e) {
this.col = e.offsetX / this.size | 0;
this.row = e.offsetY / this.size | 0;
},
},
computed: {
blockStyle() {
return {
backgroundSize: `${this.size}px ${this.size}px`,
};
},
blockCursorStyle() {
const { col, row, size } = this;
return {
transform: `translate(${col * size}px, ${row * size}px)`,
width: `${size * 0.95}px`,
height: `${size * 0.95}px`,
};
},
},<div class="block" :style="blockStyle" @mousemove="onMouseMove">
<div class="block-cursor" :style="blockCursorStyle"></div>
</div>
margin-top: $margin;
@for $i from 1 through $count {
&:nth-child(#{$i}) {
margin-top: 0;
}
}
interface ItempElement {
x: number;
y: number;
};
interface Itemp extends Array<ItempElement> {};
В документации не нашёл.
const values = (arr[0] || [])
.filter(n => arr.every(m => m.includes(n)))
.filter((n, i, a) => i === a.indexOf(n));const values = (([ set, ...sets ]) => {
return set ? [...set].filter(n => sets.every(m => m.has(n))) : [];
})(arr.map(n => new Set(n)));const values = Array
.from(arr
.flatMap(n => [...new Set(n)])
.reduce((acc, n) => acc.set(n, (acc.get(n) || 0) + 1), new Map))
.reduce((acc, n) => ((n[1] === arr.length) && acc.push(n[0]), acc), []);const values = Array
.from(arr.reduce((acc, n) => (
n.forEach(m => acc.set(m, acc.get(m) || new Set).get(m).add(n)),
acc
), new Map))
.reduce((acc, n) => (n[1].size === arr.length && acc.push(n[0]), acc), []);const values = [...arr.reduce((acc, n) => (
n = new Set(n),
acc.intersection?.(n) ?? n
), [])];
Vue.directive('сarusel', {
<select id="country"></select>
<select id="city"></select>const countryEl = document.querySelector('#country');
const cityEl = document.querySelector('#city');
countryEl.innerHTML = data
.map(n => `<option value="${n.id}">${n.country}</option>`)
.join('');
countryEl.addEventListener('change', function() {
cityEl.innerHTML = data
.find(n => n.id === this.value)
.cities
.map(n => `<option value="${n.id}">${n.city}</option>`)
.join('');
});
countryEl.dispatchEvent(new Event('change'));