$('.update').click(function() {
$('input[name="top"]').prop('checked', $('#top').val() !== 'notop');
});
cmd.hear(/^(?:передать|перевод)\s(\d+)\s(\d+)\s(.*)/i, async (ctx) => {
const [, id, amount, reason] = ctx.$match;
// ...
});
.sort((a, b) => a.categoryLevel - b.categoryLevel)
можно убратьconst groupData = (arr) => {
return arr
.sort((a, b) => a.categoryLevel - b.categoryLevel)
.reduce((acc, curr) => {
const {categoryLevel, parentCategoryId} = curr;
const index = acc.findIndex((a) =>
(a[categoryLevel - 1] || {}).categoryId === parentCategoryId);
if (index !== -1) {
acc[index][categoryLevel] = curr;
} else {
acc.push([curr]);
}
return acc;
}, [])
.map((a) => a.map((o) => o.name).join(' - '));
};
const findParents = (id, arr) => {
for (let i = 0, l = arr.length; i < l; ++i) {
const {category: {categoryId, categoryDescription}, children} = arr[i];
const obj = {categoryId, categoryDescription};
if (categoryId === id) {
return [obj];
} else {
const result = findParents(id, children);
if (result) {
return [obj, ...result];
}
}
}
return null;
};
let index = 0;
const items = data.response.items;
const timer = setInterval(() => {
if (index === items.length) {
clearInterval(timer);
return;
}
$.ajax({
url: '...?user_id=' + items[index].id + '...',
// ...
});
index++;
}, 2000);