try_files $imgdir/$imgfile /../static$uri /../static1$uri /../static2$uri /../static3$uri @image;
setInterval(() => nextButton?.click(), 5000)
поместить внутрь второго if, то всё сработает, но лучше бы - логику по интервалу вынести в useEffect, а в handlePlay - менять только флаг стейта const arrs = [
[ 1, 2, 3, 4 ],
[ 5, 6, 7, 8 ],
[ 9, 10, 11 ],
];
const result = [];
const max = Math.max(...arrs.map(n => n.length));
const index = Array(arrs.length).fill(0);
for (let i = 0; i < max; i++) {
for (let j = 0; j < index.length; j++) {
if (index[j] < arrs[j].length) {
result[result.length] = arrs[j][index[j]++];
}
}
}
const result = arrs
.reduce((acc, arr) => (
arr.forEach((n, i) => (acc[i] ??= []).push(n)),
acc
), [])
.flat();
function check(data) {
return Object.hasOwn(data, 'd') && data.m === 1;
}
const rule = {
d: /.+/,
m: /1/,
}
function check(data) {
let result = true;
for (const key in rule) {
if (!Object.hasOwn(data, key)) return false;
if(!rule[key].test(data[key])) return false;
}
return result;
}
https://jsfiddle.net/8u46rw3d/ const template = {
d: "какие то слова к которым не нужно привязываться, главное что бы был ключ d",
m: "Числовое целое поле"
};
function validateAgainstTemplate(obj, template) {
let keys = Object.keys(obj);
for (let key of keys) {
if (!template.hasOwnProperty(key)) return false; // если в шаблоне нет такого ключа
if (key === "m" && obj[key] !== 1) return false; // если значение ключа m не равно 1
}
return true; // если все проверки пройдены
}
let testObj1 = {
d: "слово",
m: 1
};
let testObj2 = {
d: "слово",
m: 23,
s: "слово 2"
};
console.log(validateAgainstTemplate(testObj1, template)); // true
console.log(validateAgainstTemplate(testObj2, template)); // false
item_id
date_day
counter
item_id + user_id
item_id
counter_1
counter_7
counter_30
// Сохраняем исходные индексы и сортируем по высоте по убыванию
const preparedData = data
.map((e, i) => ({i, e}))
.sort((a, b) => b.e.height - a.e.height);
for (const el of preparedData) {
const { height } = el.e;
// тут никогда не вернет -1, так как мы ищем элемент который точно есть в массиве - минимальный
const index = columnHeight.indexOf(Math.min(...columnHeight));
// обновляем данные массивов по выбранному индексу
columnHeight[index] += height;
columns[index].push(el);
}
// нормализуем columns
for (let i = 0; i < columns.length; ++i) {
// восстановим исходный порядок, отсортировав по сохраненному индексу по возрастанию
columns[i].sort((a, b) => a.i - b.i);
// избавимся от сохраненных индексов, оставив только исходные объекты
columns[i] = columns[i].map(({ e }) => e);
}