document.querySelector('form')?.addEventListener('submit', (event) => {
const form = new FormData(event.currentTarget);
let isValid = true;
if (form.get('name').length <= 2) {
isValid = false;
}
if (!isValid) {
// Отмена отправки формы
event.preventDefault();
}
alert(`Is Valid: ${isValid}`);
});
$('#form_test').validate({
rules: {
name: {
required: 'input[name="dzen"][value="2"]:checked'
},
phone: 'required',
email: {
required: true,
email: true
}
},
messages: {
name: 'Введите имя',
phone: 'Введите телефон',
email: 'Введите Email'
}
});
const parsedNumbers = (numbers ?? '').split(/\s+/g).map((value) => parseInt(value));
if (parsedNumbers.length === 0) {
return null;
}
const min = Math.min(...parsedNumbers);
const max = Math.max(...parsedNumbers);
return `${max} ${min}`;
const textDecoder = new TextDecoder('windows-1251');
const response = await fetch(...);
const buffer = await response.arrayBuffer();
const text = textDecoder.decode(buffer);
.hint
) пересекается с блоком А (основным текстом), и после, с использованием полученного и порогового (задаёте сами), можно решить, что делать с блоком.const clamp = (min, max, value) => Math.max(min, Math.min(max, value));
const calculateIntersection = (a, b) => {
const aRect = a.getBoundingClientRect();
const bRect = b.getBoundingClientRect();
const top = clamp(aRect.top, aRect.bottom, bRect.top);
const right = clamp(aRect.left, aRect.right, bRect.right);
const bottom = clamp(aRect.top, aRect.bottom, bRect.bottom);
const left = clamp(aRect.left, aRect.right, bRect.left);
const width = right - left;
const height = bottom - top;
const totalArea = bRect.width * bRect.height;
const intersectionArea = width * height;
const intersectionRatio = intersectionArea / totalArea;
return intersectionRatio;
};
request
.then(async (res) => ({
body: await res.blob(),
contentDisposition: res.headers.get('Content-Disposition')
}));
const computed = results.reduce(
(acc, item) => (item.data.forEach(({ name, value }) => (acc[name] = (acc[name] ?? 0) + value)), acc),
{}
);
const personInfo = {
labels: Object.keys(computed),
values: Object.values(computed)
};
const out = document.querySelector('.out');
const button = document.querySelector('button');
const a = [1, 2, 3, 4, 5];
- let y = document.querySelector('input').value;
+ const y = document.querySelector('input');
- function myFunction(ar, item) {
+ function myFunction() {
- ar = a;
- item = y;
+ const item = y.value;
- for (let i = 0; i < ar.length; i++) {
+ for (let i = 0; i < a.length; i++) {
- if (ar[i] === item) {
+ if (a[i] === item)
- return out.innerHTML += i;
+ out.innerHTML += i;
}
}
}
button.addEventListener('click', myFunction);
const toDate = (value) => value instanceof Date ? value : new Date(value);
const inDateRange = (from, to, value) =>
toDate(from).getTime() <= toDate(value).getTime() &&
toDate(to).getTime() > toDate(value).getTime();
const collected = {};
for (let index = 0; index < period.length - 1; index++) {
const current = period[index];
const next = period[index + 1];
const key = `${current} - ${next}`;
collected[key] ??= 0;
for (const entry of date) {
if (inDateRange(current, next, entry.time)) {
collected[key] += entry.total;
}
}
}
const result = Object.entries(collected).map(([key, value]) => ({ date: key, point: value }));
function example() {
if (hits.length > 0) {
return hits[0].point;
}
return undefined;
}
const blacklist = ['night', 'year', 'when', 'you', 'can'].map((word) => new RegExp(`\\b${word}\\b`, 'gi'));
const hasBlacklisted = (text) => blacklist.some((token) => token.test(text));
console.log(hasBlacklisted('night has rolled out redesigned 3d hd')); // true
console.log(hasBlacklisted('cannon camera')); // false