- if (sheep === undefined || sheep === null) sheep === 0;
+ if (sheep === undefined || sheep === null) sheep = 0;
header > div:not(:first-child) {
width: calc(100% - 36%);
padding: 68px 0 68px 48px;
border-left: 14px solid #fecb00;
background-color: #ebebeb;
}
h1, p {
margin: 0;
}
"
, в том случае, если они есть в строке.function escape(value, char = '"') {
const preparedValue = value?.toString() ?? String(value);
if (preparedValue.includes(char)) {
const escapedValue = preparedValue.replaceAll(char, char.repeat(2));
return char + escapedValue + char;
}
return preparedValue;
}
function toCSV(entries) {
return entries
.map((row) => row
.map((entry) => {
if (typeof entry === 'object') {
throw new Error('Unexpected value');
}
return escape(entry);
})
.join(',')
)
.join('\n');
}
console.assert(toCSV([]) === ``);
console.assert(toCSV([[]]) === ``);
console.assert(toCSV([['name', 'age']]) === `name,age`);
console.assert(toCSV([['name', 'age'], ['John', 30]]) === `name,age
John,30`);
console.assert(toCSV([[1, 2], ['a', 'b']]) === `1,2
a,b`);
console.assert(toCSV([[1, 2], ['a', 'b'], ['c', 'd']]) === `1,2
a,b
c,d`);
console.assert(toCSV([['"text"', 'other "long" text']]) === `"""text""","other ""long"" text"`);
window.addEventListener('DOMContentLoaded', () => {
const link = document.querySelector('[data-loop="3"] a');
if (link !== null) {
link.href = 'https://qna.habr.com/q/1232820';
}
});
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;
};