const WIDTH = 300;
const HEIGHT = 300;
const canvas = document.getElementById('canvas');
canvas.width = WIDTH;
canvas.height = HEIGHT;
const ctx = canvas.getContext('2d');
const
X = 100,
Y = 100,
A = 90,
B = 50;
const
N = 1000,
SIDE = 4,
HALF_SIDE = SIDE / 2;
const rand = (min, max) => Math.random() * (max - min) + min;
ctx.beginPath();
ctx.ellipse(X, Y, B, A, Math.PI / 2, 0, 2 * Math.PI);
ctx.stroke();
for (let i = 0; i < N; i++) {
const
x = rand(-A + HALF_SIDE, A - HALF_SIDE),
maxAbsY = (B - HALF_SIDE) / A * Math.sqrt(A * A - x * x),
y = rand(-maxAbsY, maxAbsY);
ctx.beginPath();
ctx.rect(x + X - HALF_SIDE, y + Y - HALF_SIDE, SIDE, SIDE);
ctx.stroke();
}
button.addEventListener('click', () => {
anotherButton.click();
});button.addEventListener('click', () => {
anotherButton.dispatchEvent(new Event('click', { bubbles: true }));
});
.push(x) на .push([...x]).function pyramid(n) {
const result = [];
for (let i = 0; ++i <= n;) {
const x = [];
for (let j = 0; ++j <= i; x.push(1)) ;
result.push(x);
}
return result;
}const pyramid = length => Array.from({ length }, (_, i) => Array(i + 1).fill(1));
data: () => ({
questions: [
{
text: '2 x 2?',
answers: [ '5', '3', '69', '187' ],
},
{
text: '...',
answers: [ '...', '...', ... ],
},
...
],
}) ,props: [ 'text', 'answers', 'value' ],<div>{{ text }}</div>
<div v-for="n in answers">
<label>
<input
type="radio"
:checked="n === value"
@change="$emit('input', n)"
>
{{ n }}
</label>
</div>props: [ 'questions' ],data: () => ({
index: 0,
answers: [],
}),<div v-if="index < questions.length">
вопрос
</div>
<div v-else>
результаты
</div><question
v-bind="questions[index]"
v-model="answers[index]"
/>:disabled="!answers[index]"; б) скрывать - v-show="answers[index]"):<button @click="index++">дальше</button><div v-for="(n, i) in questions">
{{ n.text }} - {{ answers[i] }}
</div>
const filterObject = (obj, values) =>
Object.entries(obj).reduce((acc, [ k, v ]) => (
values.indexOf(v) !== -1 && (acc[k] = v),
acc
), {});
const result = filterObject(a, b);const filterObject = (obj, filter) =>
Object.fromEntries(Object.entries(obj).filter(n => filter(...n)));
const result = filterObject(a, (k, v) => b.includes(v));
return this.$store.authInfothis.$store.state.authInfo?
Объект FileReader позволяет веб-приложениям асинхронно читать содержимое файлов
onFileChange({ target: { files: [ file ] } }) {
if (file) {
const reader = new FileReader();
reader.addEventListener('load', e => {
this.fileinput = e.target.result;
console.log(this.fileinput);
});
reader.readAsText(file);
}
},
const flat = arr =>
(arr || []).reduce((acc, { children, ...n }) => {
if (n.isExpanded || !children) {
acc.push(n, ...flat(children));
} else {
acc.push({ ...n, children });
}
return acc;
}, []);isExpanded: false у кого-то из предков уровнем выше родительского, тоconst flat = arr =>
(arr || []).reduce((acc, { children, ...n }) => {
const flatChildren = flat(children);
if (n.isExpanded || !children) {
acc.push(n, ...flatChildren);
} else {
acc.push({ ...n, children: flatChildren });
}
return acc;
}, []);
:class="form.FirstName !== null ? form.FirstName ? 'input-successes' : 'input-error' : ''":class="{ 'input-successes': form.FirstName, 'input-error': form.FirstName === false }":class="form.FirstName !== null && [ 'input-error', 'input-successes' ][+form.FirstName]":class="({ true: 'input-successes', false: 'input-error' })[form.FirstName]"
this.update = () => {
const w = this.w / 2;
const h = this.h / 2;
this.x = Math.max(w, Math.min(W - w, this.x + this.dx));
this.y = Math.max(h, Math.min(H - h, this.y + this.dy));
};document.addEventListener('keydown', e => {
switch (e.key) {
case 'ArrowLeft': pl.dx = -pl.speed; break;
case 'ArrowRight': pl.dx = pl.speed; break;
case 'ArrowUp': pl.dy = -pl.speed; break;
case 'ArrowDown': pl.dy = pl.speed; break;
}
});
document.addEventListener('keyup', e => {
switch (e.key) {
case 'ArrowLeft':
case 'ArrowRight': pl.dx = 0; break;
case 'ArrowUp':
case 'ArrowDown': pl.dy = 0; break;
}
});
state = {
likes: localStorage.getItem('likes') | 0,
}
plus = () => {
this.setState(({ likes }) => ({
likes: likes + 1,
}), () => localStorage.setItem('likes', this.state.likes));
}
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"].