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);
}
<svg width="320px" height="320px" viewBox="0 0 16 16">
<path fill="none" stroke="#333" stroke-width="2" d="
m 3 10
c 0 4 8 4 8 0
q 0 -2 -4 -3
q -4 -1 -4 -3
c 0 -4 8 -4 8 0
"></path>
</svg>
<svg width="175px" height="175px" viewBox="0 0 16 16">
<path fill="none" stroke="#333" stroke-width="2" d="
m 3 10
c 0 4 8 4 8 0
c 0 -4 -8 -2 -8 -6
c 0 -4 8 -4 8 0
"></path>
</svg>
$MONGODUMP_PATH -d $MONGO_DATABASE --excludeCollection sessions --excludeCollection analytics --excludeCollection counts
data.reduce((acc, curr, i) => [...acc, ...data.slice(i + 1).map((item) => `${curr} - ${item}`)], []);