ракета пролетела всю длину экрана и вышла за пределы экрана(тут мой скрипт при помощи splice удаляет ракету из массива ракет)
for (let i = this.rockets.length; i--; ) {
const rocket = this.rockets[i];
if (rocket.type === 'right' && this._isCollideFlyLeft(rocket)) {
this.flyLeft.energy -= 10;
this.rockets.splice(i, 1);
} else if (rocket.type === 'left' && this._isCollideFlyRight(rocket)) {
this.flyRight.energy -= 10;
this.rockets.splice(i, 1);
} else if (
rocket.xCoord + rocket.width >= this.fieldEl.offsetWidth ||
rocket.xCoord <= 0
) {
this.rockets.splice(i, 1);
} else {
rocket.move();
}
}
const extend = (target, source) => Object
.entries(source instanceof Object ? source : {})
.reduce((acc, [ k, v ]) => {
acc[k] = v instanceof Object ? extend(acc[k], v) : k in acc ? acc[k] : v;
return acc;
}, target instanceof Object ? target : {});
extend(patient, donor);
const onInput = () => $button.prop('disabled', !$inputs.get().every(n => $(n).val()));
const $button = $('селектор кнопки');
const $inputs = $('селектор инпутов').on('input', onInput);
onInput();
const button = document.querySelector('селектор кнопки');
const inputs = [...document.querySelectorAll('селектор инпутов')];
const onInput = () => button.disabled = inputs.some(n => !n.value);
inputs.forEach(n => n.addEventListener('input', onInput));
onInput();
$('#name').on('input', function() {
$('.cell').text(i => this.value[i] || '');
});
document.querySelector('#name').addEventListener('input', e => {
document.querySelectorAll('.cell').forEach((n, i) => {
n.textContent = e.target.value[i] || '';
});
});
arr.map(n => ({
id: n.id.value,
title: n.title.value,
slug: n.slug.value
}))
arr.map(n => Object.entries(n).reduce((acc, [ k, v ]) => (acc[k] = v.value, acc), {}))
arr.map(n => Object.keys(n).reduce((acc, k) => ({ ...acc, [k]: n[k].value }), {}))
arr.map(n => Object.assign({}, ...Object.values(n).map(m => ({ [m.title.toLowerCase()]: m.value }))))
const links = [
'https://youtu.be/fi5LDM9ppuc',
'https://www.youtube.com/embed/fi5LDM9ppuc',
];
const newLinks = links.map(n => `https://www.youtube.com/watch?v=${n.split('/').pop()}`);
const invertTree = ({ value, left, right }) => {
const node = { value };
if (left) {
node.right = invertTree(left);
}
if (right) {
node.left = invertTree(right);
}
return node;
};
[data-type="
на [data-type*="
. fetch(filename)
.then(r => r.text())
.then(r => r.split('\n').map(n => {
const [ key, val ] = n.split(' = ');
return { [key]: val };
}))
.then(arr => {
// ну вот вам ваши объекты
});
r.split('\n')
на r.match(/\$[a-z0-9-]+ = #[0-9a-f]{6}/g)
, например. const months = Array.from({ length: 12 }, (n, i) => {
return new Date(0, i).toLocaleString('en', { month: 'short' }).toLowerCase();
});
const newArr = arr.map(({ data, ...item }) => (
data.forEach((n, i) => item[months[i]] = n),
item
));
link
, screen
- без цифр..screen
определяете ещё один класс:.screen {
display: none;
}
.screen.active {
display: flex;
}
$(document).on('click', '.link', function() {
const $screen = $(this).next().toggleClass('active');
$('.screen.active').not($screen).removeClass('active');
});
function combine(keys, values) {
const length = Math.max(0, ...values.map(n => n.length));
const arr = Array.from({ length }, () => ({}));
values.forEach((n, i) => n.forEach((m, j) => arr[j][keys[i]] = m));
return arr;
}
const newArray = combine([ 'name', 'id' ], [ nameArray, idArray ]);
const widgetData = [
{ name: 'something', value: 14, date: '02.08.2018' },
{ name: 'something', value: 43, date: '03.08.2018' },
{ name: 'something', value: 44, date: '04.08.2018' },
{ name: 'something', value: 38, date: '05.08.2018' },
];
const startDate = '01.08.2018';
const endDate = '25.08.2018';
const widgetDataObj = widgetData.reduce((acc, n) => (acc[n.date] = n, acc), {});
const start = new Date(startDate.split('.').reverse().join('-'));
const end = new Date(endDate.split('.').reverse().join('-'));
const result = [];
for (; start <= end; start.setDate(start.getDate() + 1)) {
const date = start.toLocaleDateString('ru-RU');
result.push(widgetDataObj[date] || {
name: 'something',
value: 0,
date,
});
}
console.log(result);
const filterItem = (list, item) =>
list.map(n => ({
...n,
items: n.items.filter(m => m.id !== item.id),
}));
function removeItem(list, { id }) {
list.forEach(({ items: n }) => {
n.splice(0, n.length, ...n.filter(m => m.id !== id));
});
}
function recalc() {
const register = +$('[name="radio-register"]:checked').data('value');
$('#price_result, #price1').text(register
? register +
+$('#count-class option:selected').data('value') +
+$('[name="radio-znak"]:checked').data('value')
: 0
);
}
$('input[name="radio-znak"], input[name="radio-register"], #count-class').change(recalc);
recalc();