function formatDate(str) {
const d = new Date(str.replace('_', ' 1, '));
d.setMonth(d.getMonth() - 1);
return d.toLocaleDateString('en-US', {
month: 'short',
year: 'numeric',
}).replace(' ', '_');
}
formatDate('Feb_2021') // "Jan_2021"
formatDate('Jan_2000') // "Dec_1999"
this.setState(({ items }) => ({
items: items.map((n, i) => ({ ...n, id: i })),
}));state = {
items: this.props.items.map((n, i) => ({ ...n, id: i })),
}
g на самом деле отсутствует. Смотрите внимательнее, куда вы его попытались вписать.
computed: {
grouped() {
return this.arr.reduce((acc, n) => ((acc[n.group] ??= []).push(n), acc), {});
},
},<v-expansion-panels>
<v-expansion-panel v-for="(items, groupName) in grouped">
<v-expansion-panel-header>{{ groupName }}</v-expansion-panel-header>
<v-expansion-panel-content>
<div v-for="n in items">{{ n.name }}</div>
</v-expansion-panel-content>
</v-expansion-panel>
</v-expansion-panels>
str.match(/(?<=\. ).+(?= \(%\))/)[0]
// или
str.replace(/^.*?\. | \(%\).*$/g, '')
// или
str.split('. ').pop().split(' (%)').shift()
string valuelong index = value[l];'1' ('2', '3', ...) будет неявно преобразовано в 1 (2, 3, ...). Зря. Так не будет. Вы получите код соответствующего символа. Ваше счастье, коды цифровых символов расположены один за другим, в порядке возрастания соответствующих им цифр, так что достаточно вычесть код нуля, чтобы получить нужное число:long index = value[l] - '0';
const filter = (arr, str) => (arr || [])
.map(n => ({ ...n, children: filter(n.children, str) }))
.filter(n => n.name.includes(str) || n.children.length);computed: {
filteredItems() {
return filter(this.items, this.search);
},
},
computed: {
total() {
return this.value1 * this.value2 + this.checkbox * 1000;
},
},
this.getRandomZ() не вычисляется
const getRandomPolynom = () => {
const [ A, B, C, D ] = Array.from({ length: 4 }, this.getRandomZ);
return x => A * x ** 4 + B * x ** 3 - C * x ** 2 - D * x + 10;
};
const wrapper = document.querySelector('.wrap');
const html = '<div class="item active">5</div>';const last = wrapper.lastElementChild;
// или
const last = wrapper.querySelector(':scope > :last-child');
// или
const last = wrapper.children[wrapper.children.length - 1];
// или
const [ last ] = Array.prototype.slice.call(wrapper.children, -1);last.insertAdjacentHTML('beforebegin', html);
// или
last.before(...new DOMParser().parseFromString(html, 'text/html').body.childNodes);
// или
wrapper.insertBefore(document.createRange().createContextualFragment(html), last);
// или
last.outerHTML = html + last.outerHTML;
const containerSelector = '.card';
const selectSelector = `${containerSelector} select`;
const key = 'name';
const attr = `data-${key}`;
const attrSelector = `[${attr}]`;$(selectSelector).change(function() {
$(this)
.closest(containerSelector)
.find(attrSelector)
.hide()
.filter(`[${attr}="${this.value}"]`)
.show();
}).val(defaultValueSelected).trigger('change');
// или
const selects = document.querySelectorAll(selectSelector);
const onChange = ({ target: t }) => t
.closest(containerSelector)
.querySelectorAll(attrSelector)
.forEach(n => n.style.display = t.value === n.dataset[key] ? 'block' : 'none');
selects.forEach(n => {
n.value = defaultValueSelected;
n.addEventListener('change', onChange);
n.dispatchEvent(new Event('change'));
});
const tree = ref(null)return {
tree,
...<el-tree
ref="tree"
...tree.value.getCheckedKeys().
export default ({ filter, checked, onChange, children }) => (
<div>
<label>
<input
type="checkbox"
name={filter}
onChange={() => onChange(filter)}
checked={checked}
/>
{children}
</label>
</div>
);
function getURLs($arr, $path = []) {
$urls = [];
foreach ($arr as $item) {
array_push($path, $item['slug']);
array_push($urls, '/'.implode('/', $path).'/', ...getURLs($item['children'], $path));
array_pop($path);
}
return $urls;
}
const result = Object.values(arr.reduce((acc, n) => {
(acc[n.name] ??= ({ ...n, count: 0 })).count++;
return acc;
}, {}));function uniqueWithCount(data, key, countKey) {
const getKey = key instanceof Function ? key : n => n[key];
const unique = new Map;
for (const n of data) {
const k = getKey(n);
unique
.set(k, unique.get(k) ?? { ...n, [countKey]: 0 })
.get(k)[countKey]++;
}
return unique;
}const result = [...uniqueWithCount(arr, 'name', 'count').values()];