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;
};
@keyframes arrow {
0% {
width: 60px;
}
25% {
width: 260px;
transform: translateX(0px);
}
50%, 75% {
width: 60px;
transform: translateX(200px);
}
}
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)
};
if
.function dispatch<T>(key: DispatchKey<T>, value: DispatchValue<T>): void;
function dispatch<T>(keys: DispatchKey<T>[], iterator: (key: DispatchKey<T>) => DispatchValue<T>): void;
function dispatch<T>(
keyOrKeys: DispatchKey<T> | DispatchKey<T>[],
valueOrIterator: DispatchValue<T> | ((key: DispatchKey<T>) => DispatchValue<T>)
): void {
if (Array.isArray(keyOrKeys) && typeof valueOrIterator === 'function') {
setState((prev) => {
const updated = keyOrKeys.map((key) => valueOrIterator(key));
console.log(updated);
return prev;
});
} else {
setState((prev) => ({
...prev,
[keyOrKeys]: valueOrIterator,
}));
}
}
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);
/
) указывает на директорию, которую «просматривает» сервер. Если же открыть HTML-файл в браузере, то /
будет указывать на корень диска, например в C:/
. jsconfig.json
алиасы - так не будет работать. Либо переопределяйте алиасы в webpack, а если это CRA, сделать не так просто (вроде есть некоторые утилиты, работающие поверх CRA). Вариант второй - исправить везде импорты. 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 }));
- <Form @submit="onSubmit" :validation-schema="schema">
+ <Form @submit="onSubmit" :validation-schema="schema" validate-on-mount>
function example() {
if (hits.length > 0) {
return hits[0].point;
}
return undefined;
}