const delimiter = str.match(/\D/)[0];
// или
const delimiter = str[str.search(/\D/)];
// или
const [ delimiter ] = str.replace(/^\d+/, '');
// или
const delimiter = Array.prototype.find.call(str, n => Number.isNaN(+n));
// или
const delimiter = [...str].filter(n => !'0123456789'.includes(n)).shift();
const parent = document.querySelector('.container');
const className = 'green';
const startFrom = 4;
parent
.querySelectorAll(`:scope > :nth-child(n + ${startFrom + 1})`)
.forEach(n => n.classList.add(className));
// или
for (const n of Array.prototype.slice.call(parent.children, startFrom)) {
n.classList.add(className);
}
// или
for (let el = parent.children[startFrom]; el; el = el.nextElementSibling) {
el.classList.add(className);
}
// или, также удаляем класс (если вдруг есть) у тех, кому он не должен быть добавлен
for (let i = 0; i < parent.children.length; i++) {
parent.children[i].classList.toggle(className, i >= startFrom);
}
function createRandomArr(length, min, max) {
if (length > max - min + 1) {
throw 'такого массива быть не может';
}
const values = new Set;
for (; values.size < length; values.add(min + Math.random() * (max - min + 1) | 0)) ;
return [...values];
}
const createRandomArr = (length, min, max) => Array
.from({ length }, function() {
return this.splice(Math.random() * this.length | 0, 1);
}, Array.from({ length: max - min + 1 }, (n, i) => i + min))
.flat();
function createRandomArr(length, min, max) {
const arr = Array.from({ length: max - min + 1 }, (n, i) => min + i);
for (let i = arr.length; --i > 0;) {
const j = Math.random() * (i + 1) | 0;
[ arr[i], arr[j] ] = [ arr[j], arr[i] ];
}
return arr.slice(0, length);
}
Components can recursively invoke themselves in their own template. However, they can only do so with the name
option
const values = [ id, sum, system, date ];
.payment.innerHTML = values.map(n => `<td>${n}</td>`).join('');
// или
values.forEach(n => payment.insertCell().textContent = n);
// или
payment.append(...values.map(n => {
const td = document.createElement('td');
td.innerText = n;
return td;
}));
- function createPayment({id, sum, system, date}) {
+ function createPayment(data) {
- const values = [ id, sum, system, date ];
+ const keys = [ 'id', 'sum', 'system', 'date' ];
- values.forEach(n => payment.insertCell().textContent = n);
+ keys.forEach(n => payment.insertCell().textContent = data[n]);
мне ж понятно будет
const propsCount = 3;
.const newObj = Object.fromEntries(Object
.entries(obj)
.sort((a, b) => a[1] - b[1])
.slice(-propsCount)
);
Object
.entries(obj)
.sort((a, b) => b[1] - a[1])
.slice(propsCount)
.forEach(n => delete obj[n[0]]);
watch: {
данные: {
immediate: true,
handler(value) {
if (value какой нужен) {
делаете чего там вам надо
}
},
},
},
computed: {
данные() {
return [ this.данные1, this.данные2, /* ... */ ];
},
},
watch: {
данные: {
immediate: true,
handler(value) {
if (value.every(n => n какой нужен)) {
делаете чего там вам надо
}
},
},
},
mixin item(item)
.inform-items__item(class=`inform-items__item_bg_${item.bg}`)
app.directive(directives);
str.match(/(?<=>)\d+/g) ?? []
// или
str.match(/>\d+/g)?.map(n => n.slice(1)) ?? []
// или
Array.from(str.matchAll(/>(\d+)/g), n => n[1])
''.concat(...Array.from(str, n => n.repeat(2)))
// или
str.replace(/./g, '$&$&')
// или
str.replace(/./g, m => Array(3).join(m))
// или
str.replace(/(?=.)/g, (m, i) => str[i])
// или
[...str].flatMap(n => Array(2).fill(n)).join('')
// или
[].map.call(str, n => `${n}${n}`).join``
// или
str.split('').reduce((acc, n) => acc + n + n, '')
arr.reduce((acc, n, i) => (
(!i || n === 1) && acc.push([]),
acc[acc.length - 1].push(n),
acc
), [])
const index = arr.reduce((min, n, i, a) => a[min]?.length <= n.length ? min : i, -1);
if (index !== -1) {
arr[index] = arr[index][0].toUpperCase() + arr[index].slice(1);
}
const [ indexes ] = arr.reduce((min, n, i) => (
n.length < min[1] && (min = [ [], n.length ]),
n.length === min[1] && min[0].push(i),
min
), [ [], Infinity ]);
indexes.forEach(n => arr[n] = arr[n].replace(/./, m => m.toUpperCase()));