const { position: { x, y }, cell_radius, food_size, food } = this;
const isIntersects = item =>
(item.x - x) ** 2 + (item.y - y) ** 2 <= (cell_radius + food_size) ** 2;
food.splice(0, food.length, ...food.filter(n => !isIntersects(n)));
// или
for (let i = food.length; i--;) {
if (isIntersects(food[i])) {
food.splice(i, 1);
}
}
// или
let countEaten = 0;
for (let i = 0; i < food.length; i++) {
food[i - countEaten] = food[i];
countEaten += isIntersects(food[i]);
}
food.length -= countEaten;
const index = str.search(/\d/);
.const index = str.match(/^(\D*\d)?/)[0].length - 1;
// или
const index = [...str].findIndex(n => !Number.isNaN(+n));
// или
let index = -1;
for (let i = 0; i < str.length; i++) {
if ('0123456789'.includes(str[i])) {
index = i;
break;
}
}
@submit.prevent
. Или клик по кнопке обрабатывайте иначе: @click.prevent="addGuest"
. const rows = useMemo(() => data.length
? data[0].arr.map((n, i) => data.map(m => m.arr[i]))
: []
, [ data ]);
<table>
<tbody>
{rows.map(n => <tr>{n.map(m => <td>{m}</td>)}</tr>)}
</tbody>
</table>
store.dispatch('config/loadMain').then(() => {
new Vue({
...
При движении вверх или влево координаты искажаются.
$('селектор картинок').unwrap();
function unwrap(element) {
const wrapper = element.parentNode;
const fragment = new DocumentFragment();
DocumentFragment.prototype.append.apply(fragment, wrapper.childNodes);
wrapper.parentNode.replaceChild(fragment, wrapper);
}
// или
const unwrap = ({ parentNode: wrapper }) =>
wrapper.replaceWith(...wrapper.childNodes);
document.querySelectorAll('селектор картинок').forEach(unwrap);
const newArr = arr.map((n, i) => n.repeat(i + 1));
const newArr = arr.map((n, i) => Array(i + 1).fill(n).join(''));
const newArr = arr.map((n, i) => Array(i + 2).join(n));
const newArr = [];
for (let i = 0; i < arr.length; i++) {
let str = '';
for (let j = 0; j <= i; j++) {
str += arr[i];
}
newArr.push(str);
}
const newArr = [];
for (const n of arr) {
let str = '';
while ((str = str.concat(n)).length <= newArr.length) ;
newArr[newArr.length] = str;
}
const select = document.querySelector('[name="auto_model"]');
select.append(...Object.values([...select].reduce((acc, n) => {
if (n.value) {
const k = n.dataset.mark;
acc[k] || ((acc[k] = document.createElement('optgroup')).label = k);
acc[k].append(n);
}
return acc;
}, {})));
/\w{6}/.test(password)
At least six characters long
^
- начало строки, $
- конец); символов может быть больше шести (квантификатор {}
позволяет указывать диапазон значений, верхнюю границу оставляем открытой). Т.е., правильно будет так:/^\w{6,}$/.test(password)
\w
- не alphanumeric, это ещё и _
, так что придётся перечислить нужные символы в более явном виде. Кроме того, вместо четырёх отдельных выражений можно сделать одно:/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[a-zA-Z\d]{6,}$/.test(password)
document.querySelector('button').addEventListener('click', function() {
const val = +document.querySelector('#elem1').value;
const sign = Math.sign(val);
document.querySelector('#str').innerHTML = Array
.from({ length: val * sign + 1 }, (n, i) => val - i * sign)
.join('<br>');
});
$('.nextArrow, .backArrow').on('animationend', e => e.target.style.animation = '');
$ids = explode(',', $arr['ids']);
$newArr = array_map(function($n, $i) use($arr) {
return [ $n, $arr['src'][$i] ];
}, $ids, array_keys($ids));
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.6.10/vue.js"></script>
<div id="app" @dragover.prevent="">
<button v-if="done" @click="init">ещё раз</button>
<div v-else>
<div class="questions">
<div
v-for="n in questions"
:class="[ 'card', { hidden: n.done } ]"
draggable="true"
@dragstart="onDragStart($event, n)"
>{{ n.question }}</div>
</div>
<div class="answers">
<div
v-for="n in answers"
:class="[ 'card', { hidden: n.done } ]"
@drop="onDrop(n)"
>{{ n.answer }}</div>
</div>
</div>
</div>
$side: 75px;
.questions,
.answers {
width: $side * 3;
height: $side * 3;
margin: 10px;
display: inline-block;
}
.card {
display: inline-flex;
justify-content: center;
align-items: center;
border: 1px solid silver;
box-sizing: border-box;
width: $side;
height: $side;
background: red;
color: white;
font-weight: bold;
font-family: monospace;
}
.hidden {
visibility: hidden;
}
new Vue({
el: '#app',
data: () => ({
dragged: null,
items: [
{ question: '2 x 2', answer: 4 },
{ question: '5 x 6', answer: 30 },
{ question: '7 x 7', answer: 49 },
{ question: '8 x 4', answer: 32 },
{ question: '7 x 5', answer: 35 },
{ question: '6 x 9', answer: 54 },
{ question: '9 x 8', answer: 72 },
{ question: '6 x 8', answer: 48 },
{ question: '9 x 7', answer: 63 },
].map(n => (n.done = false, n)),
questions: [],
answers: [],
}),
computed: {
done() {
return this.items.every(n => n.done);
},
},
methods: {
onDragStart(e, item) {
this.dragged = item;
},
onDrop(item) {
if (item === this.dragged) {
item.done = true;
} else {
alert('Ты дурак, да?');
}
},
init() {
const { items } = this;
items.forEach(n => n.done = false);
this.questions = [...this.items].sort(() => 0.5 - Math.random());
this.answers = [...this.items].sort(() => 0.5 - Math.random());
},
},
created() {
this.init();
document.addEventListener('dragend', () => this.dragged = null);
},
});