<div class="wrapper">
.const containerSelector = '.wrapper';
const headerSelector = '.request__nav__item';
const contentSelector = '.request__field';
const activeClass = 'active';
$(containerSelector).on('click', headerSelector, function(e) {
const $headers = $(headerSelector, e.delegateTarget);
const index = $headers.index(this);
$headers.removeClass(activeClass).eq(index).addClass(activeClass);
$(contentSelector, e.delegateTarget).hide().eq(index).fadeIn();
}).each(function() {
$(headerSelector, this).first().click();
});
$('a').click(function() {
const $tabs = $('.splCont');
const $tab = $tabs.eq($(this).index()).toggle('normal');
$tabs.not($tab).hide('normal');
return false;
});
const toSeconds = str => str
.split(':')
.reverse()
.reduce((acc, n, i) => acc + n * (60 ** i), 0);
const sumDiagonals = matrix =>
matrix.reduce((acc, n, i) => {
acc.principal += n[i];
acc.secondary += n[n.length - i - 1];
return acc;
}, {
principal: 0,
secondary: 0,
});
const result = [];
for (const n of numbers) {
if (!objects.some(m => m.number === n)) {
result.push(n);
}
}
const result = numbers.filter(function(n) {
return !this.has(n);
}, new Set(objects.map(n => n.number)));
const result = (function get(exclude, i, n = numbers[--i]) {
return i >= 0
? get(exclude, i).concat(~exclude.indexOf(n) ? [] : n)
: [];
})(objects.map(n => n.number), numbers.length);
const result = Object.values(objects.reduce(
(acc, n) => (delete acc[n.number], acc),
numbers.reduce((acc, n) => (acc[n] = n, acc), {})
));
const result = Array.from(objects.reduce(
(acc, n) => (acc.delete(n.number), acc),
new Map(numbers.map(n => [ n, n ]))
).values());
const newArr = [...arr]
.sort((a, b) => a.name.localeCompare(b.name) || (a.price - b.price))
.filter((n, i, a) => n.name === a[i - 1]?.name);
const newArr = [...arr]
.sort((a, b) => a.name.localeCompare(b.name) || (a.price - b.price))
.filter((n, i, a) => n.name === a[i - 1]?.name || n.name !== a[i + 1]?.name);
const newArr = [...arr]
.sort((a, b) => a.price - b.price)
.filter((n, i, a) => n !== a.find(m => m.name === n.name));
const newArr = [...arr].sort((a, b) => a.price - b.price);
Object
.values(newArr.reduce((acc, n) => ((acc[n.name] ??= []).push(n), acc), {}))
.forEach(n => n.length !== 1 && newArr.splice(newArr.indexOf(n[0]), 1));
def replacer(m):
val = m.group(0)
return str(int(val or '0') + 1).rjust(len(val), '0')
def increment(s):
return re.sub(r'\d*$', replacer, s, 1)
const values = Object.values(obj);
const min = Math.min(...values);
const max = Math.max(...values);
const [ min, max ] = Object
.values(obj)
.reduce(([ min, max ], n) => [
n < min ? n : min,
n > max ? n : max,
], [ Infinity, -Infinity ]);
let min = Infinity;
let max = -Infinity;
for (const k in obj) {
if (obj.hasOwnProperty(k)) {
const v = obj[k];
(min > v) && (min = v);
(max < v) && (max = v);
}
}
const mustStay = n => n !== null;
.const newArr = arr.map(n => ({
...n,
array2: n.array2.filter(mustStay),
}));
for (let i = 0; i < arr.length; i++) {
const a = arr[i].array2;
for (let j = 0; j < a.length; j++) {
if (!mustStay(a[j])) {
for (let k = j--; ++k < a.length; a[k - 1] = a[k]) ;
a.pop();
}
}
}
// или
arr.forEach(n => {
n.array2.reduceRight((_, n, i, a) => mustStay(n) || a.splice(i, 1), 0);
});
// или
(function next(i, { array2: a } = arr[i] ?? {}) {
if (a) {
a.splice(0, a.length, ...a.filter(mustStay));
next(-~i);
}
})(0);
// или
for (const { array2: a } of arr) {
a.length -= a.reduce((acc, n, i) => (
a[i - acc] = n,
acc + !mustStay(n)
), 0);
}
const table = document.querySelector('table');
const columnIndex = Object.fromEntries(Array.from(
table.tHead.rows[0].cells,
n => [ n.innerText.toLowerCase(), n.cellIndex ]
));
function onChange() {
const filters = Object.entries(Array.prototype.reduce.call(
document.querySelectorAll('.list-group :checked'),
(acc, n) => ((acc[columnIndex[n.name]] ??= []).push(n.value), acc),
{}
));
for (const { rows } of table.tBodies) {
for (const tr of rows) {
tr.hidden = filters.some(n => !n[1].includes(tr.cells[n[0]].innerText));
}
}
}
document.querySelectorAll('.list-group').forEach(n => {
n.addEventListener('change', onChange);
});
кнопки на самой папке не нужны
<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>
const getElementsWithDepth = (el, depth = 0) =>
[...el.children].reduce((acc, n) => (
acc.push(...getElementsWithDepth(n, depth + 1)),
acc
), [ { el, depth } ]);
function getElementsWithDepth(root) {
const result = [];
for (const stack = [ [ root, 0 ] ]; stack.length;) {
const [ el, depth ] = stack.pop();
result.push({ el, depth });
stack.push(...Array.from(el.children, n => [ n, -~depth ]).reverse());
}
return result;
}
// или
const getElementsWithDepth = root =>
Array.prototype.reduce.call(
root.querySelectorAll('*'),
(acc, n) => {
acc.push({ el: n, depth: 1 });
for (; (n = n.parentNode) !== root; acc[acc.length - 1].depth++) ;
return acc;
},
[ { el: root, depth: 0 } ]
);
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;
}