const types = {
p: ['count', 'name', 'info', 'price'],
c: ['count', 'name', 'info', 'price'],
m: ['value', 'price'],
disk: ['count', 'name', 'price'],
radio: ['name', 'price'],
button: ['value', 'price'],
checkbox: ['name', 'price']
};
const values = {
name: optionName,
price: optionPrice,
value: optionValue,
count: optionCount,
info: optionChars
};
const result = types[type].reduce((acc, curr) => ({...acc, [curr]: values[curr]}), {});
if (type === 'checkbox') {
this.selectedOptions[type][`check${data.checkId}`] = result;
} else {
this.selectedOptions[type === 'disk' ? type + t.diskNumber : type] = result;
}
$('.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;
};