const mustStay = n => n !== null;
.const newArr = arr.map(n => ({
...n,
array2: n.array2.filter(mustStay),
}));
arr.forEach(n => n.array2.reduceRight((_, n, i, a) => mustStay(n) || a.splice(i, 1), 0));
// или
for (let i = 0; i < arr.length; i++) {
const a = arr[i].array2;
a.splice(0, a.length, ...a.filter(mustStay));
}
// или
for (const { array2: a } of arr) {
let numDeleted = 0;
for (const [ i, n ] of a.entries()) {
a[i - numDeleted] = n;
numDeleted += !mustStay(n);
}
a.length -= numDeleted;
}
const columnIndex = {
color: 0,
fruit: 1,
};
function filter() {
const filters = Object.entries(Array
.from(document.querySelectorAll('.list-group :checked'))
.reduce((acc, n) => ((acc[n.name] ??= []).push(n.value), acc), {})
);
document.querySelectorAll('table tbody tr').forEach(n => {
n.style.display = filters.some(([ k, v ]) => !v.includes(n.cells[columnIndex[k]].innerText))
? 'none'
: 'block';
});
}
document.querySelectorAll('.list-group').forEach(n => n.addEventListener('change', filter));
кнопки на самой папке не нужны
<template #append="{ leaf }">
<template v-if="leaf">
<v-btn small><v-icon>mdi-plus-box</v-icon></v-btn>
<v-btn small><v-icon>mdi-file-edit-outline</v-icon></v-btn>
<v-btn small><v-icon>mdi-content-save-settings</v-icon></v-btn>
<v-btn small><v-icon>mdi-minus-circle-outline</v-icon></v-btn>
</template>
</template>
SELECT * FROM 'users'
function getDays(year, month) {
const days = [];
const d = new Date(year, month, 1);
let week = 1;
while (d.getMonth() === month) {
const date = d.getDate();
const day = d.getDay();
days.push({
day: date,
weeknumber: (day === 1 || date === 1) ? week : false,
weekday: d.toLocaleString('en-US', { weekday: 'short' }),
});
d.setDate(date + 1);
week += !day;
}
return days;
}
text.match(RegExp(str, 'g'))?.length ?? 0
text.split(str).length - 1
<TreePicker
locale={{
searchPlaceholder: 'hello, world!!',
}}
const flatObj = obj =>
Object.entries(obj).reduce((acc, [ k, v ]) => (
v instanceof Object && !Array.isArray(v)
? Object.assign(acc, flatObj(v))
: acc[k] = v,
acc
), {});
document.querySelectorAll('h2').forEach(n => {
const [ season, , episode ] = n.innerText.split(' ');
if (+episode === 1) {
n.id = `season-${season}`;
}
});
[...document.querySelectorAll('h2')]
.filter(n => n.innerText.endsWith(', 1 серия'))
.forEach((n, i) => n.id = `season-${i + 1}`);
document.querySelectorAll('h2').forEach((n, i, a) => {
const prev = i && a[i - 1].innerText.match(/\d+/)[0];
const curr = n.innerText.match(/\d+/)[0];
if (curr !== prev) {
n.id = `season-${curr}`;
}
});
Array
.from(document.querySelectorAll('h2'))
.reduce((acc, n) => (acc[parseInt(n.innerText)] ??= n, acc), [])
.forEach((n, i) => n.id = `season-${i}`);
function rotateArray($arr, $shift) {
$shift %= count($arr);
array_unshift($arr, ...array_splice($arr, -$shift));
return $arr;
}
$arr = range(1, 7);
echo implode(', ', rotateArray($arr, 1)); // 7, 1, 2, 3, 4, 5, 6
echo implode(', ', rotateArray($arr, -3)); // 4, 5, 6, 7, 1, 2, 3
echo implode(', ', rotateArray($arr, 69)); // 2, 3, 4, 5, 6, 7, 1
<div class="slider">
$('.slick').slick({
data-category="orange"
var filterClass = $(this).data('category');
$('.slick').slick('slickFilter', filterClass);
$('.category__menu').on('click', 'li', function() {
$('.slider').slick('slickUnfilter');
const category = $(this).data('category');
if (category !== 'allPost') {
$('.slider').slick('slickFilter', `.${category}`);
}
});
const transpose = matrix => Array.from(
{ length: matrix[0]?.length ?? 0 },
(_, i) => matrix.map(n => n[i])
);
function transpose(matrix) {
const result = Array(matrix.length && matrix[0].length);
for (let i = 0; i < result.length; i++) {
result[i] = [];
for (let j = 0; j < matrix.length; j++) {
result[i][j] = matrix[j][i];
}
}
return result;
}
const groupAdjacent = (arr, newGroup) =>
arr.reduce((acc, n, i, a) => (
(!i || newGroup(n, a[~-i])) && acc.push([]),
acc[~-acc.length].push(n),
acc
), []);
const result = groupAdjacent(arr, (c, p) => c !== -~p);
function group(data, key) {
const grouped = new Map;
let i = -1;
for (const n of data) {
const k = key(n, ++i);
grouped.set(k, grouped.get(k) ?? []).get(k).push(n);
}
return grouped;
}
const result = [...group(arr, (n, i) => n - i).values()];
const [ form, setForm ] = useState({
login: '',
password: '',
});
const onChange = ({ target: t }) => setForm({ ...form, [t.name]: t.value });
<input name="login" value={form.login} onChange={onChange} />
<input name="password" value={form.password} onChange={onChange} />
$('.js-cropped-word').text((i, text) => text.replace(/(?<=\S{19,}).+/, '...'));
В Сафари не работает
document.querySelectorAll('.js-cropped-word').forEach(n => {
n.textContent = n.textContent.replace(/(\S{19}).+/, '$1...');
});
const max = 19;
for (const n of document.getElementsByClassName('js-cropped-word')) {
const words = n.innerText.split(' ');
const i = words.findIndex(n => n.length > max);
if (i !== -1) {
words.length = i + 1;
words[i] = words[i].slice(0, max) + '...';
n.innerText = words.join(' ');
}
}