const [users, setUsers] = useState({user:['user1', 'user2', 'user3']});
setUsers(users.user.filter((item,i) => i !== index));
const list = users.user.map(...
class DoublyLinkedList {
constructor() {
this.size = 0;
this.head = null;
this.tail = null;
}
add(value, index) {
index ??= this.size;
const next = this.searchByIndex(index);
const prev = next ? next.prev : this.tail;
const node = { value, next, prev };
prev || (this.head = node);
next || (this.tail = node);
prev && (prev.next = node);
next && (next.prev = node);
this.size++;
}
_remove(node) {
if (node) {
node.prev || (this.head = node.next);
node.next || (this.tail = node.prev);
node.prev && (node.prev.next = node.next);
node.next && (node.next.prev = node.prev);
this.size--;
}
}
removeByValue(value) {
this._remove(this.searchByValue(value));
}
removeByIndex(index) {
this._remove(this.searchByIndex(index, true));
}
searchByIndex(index, strict) {
if (!(index >= 0 && index <= this.size - !!strict)) {
throw 'invalid index';
}
let node = this.head;
while (index--) {
node = node.next;
}
return node;
}
searchByValue(value, startIndex = 0) {
let node = this.searchByIndex(startIndex, true);
while (node && node.value !== value) {
node = node.next;
}
return node;
}
}
methods: {
classes: obj => ({
'current-active': obj.progress.current > 0,
}),
...
},
:class="classes(cutLine)"
chunkSize = 2
chunksNum = len(string) - chunkSize + 1
chunks = [ string[i:i + chunkSize] for i in range(0, chunksNum) ]
<Route path="/products" component={Products} />
exact
.return <h1>Product# {match.slug}</h1>;
match.params.slug
. function max(data, key = n => n) {
const getVal = key instanceof Function ? key : n => n[key];
return Array.prototype.reduce.call(data, (max, n) => {
const val = getVal(n);
return max[0] > val ? max : [ val, n ];
}, [ -Infinity, undefined ])[1];
}
const { text } = max(arr, n => n.text.length);
const oldest = max(arr, 'age');
const remove = {
from: 5,
exclude: [ 9, 10, 11 ],
};
$('table tr').each(function() {
$(this)
.children()
.filter(i => i >= remove.from && !remove.exclude.includes(i))
.remove();
});
function getWeekdaysOfMonth(year, month) {
const date = new Date(year, --month, 1);
const result = [];
while (date.getMonth() === month) {
result.push(date.toLocaleString('ru-RU', {
month: 'long',
day: 'numeric',
weekday: 'long',
}));
date.setDate(date.getDate() + 1);
}
return result;
}
const weekdaysOfDecember2020 = getWeekdaysOfMonth(2020, 12);
но как поступить если я не хочу забирать дни недели из стандартного объекта. а взять из их своего массива?
const weekdays = [
'воскресенье',
'это понедельник',
'а это вторник',
'конечно же среда',
'четверг',
'пятница - прямо после четверга',
'суббота, рабочая неделя окончена',
];
const getWeekdaysOfMonth = (year, month) => Array.from(
{ length: new Date(year, month--, 0).getDate() },
(n, i) => {
const d = new Date(year, month, i + 1);
return d.toLocaleString('ru-RU', {
month: 'long',
day: 'numeric',
}) + ', ' + weekdays[d.getDay()];
});
const weekdaysOfFebruary2021 = getWeekdaysOfMonth(2021, 2);
document.querySelector('.products__body').addEventListener('click', e => {
const item = e.target.closest('.card-preview__item');
if (item) {
e.preventDefault();
const { srcset } = item.querySelector('source');
item.closest('.card').querySelector('.card-head__image source').srcset = srcset;
}
});
function merge(...$arrays) {
$result = [];
foreach ($arrays as $arr) {
foreach ($arr as $key => $values) {
if (!isset($result[$key])) {
$result[$key] = [];
}
for ($i = 0; $i < count($values); $i++) {
$result[$key][$i] = ($result[$key][$i] ?? 0) + $values[$i];
}
}
}
return $result;
}
$arr = merge($arr1, $arr2);
нужно отлавливать дата атрибуты и если эти дата атрибуты совпадают с дата атрибутами других блоков то вешать класс на блоки
on: {
slideChange() {
const index = this.realIndex;
document.querySelectorAll('.lol').forEach((n, i) => n.classList.toggle('active', i === index));
},
},
.clients__picture
все .lol
, вырезаете обработчик slideChange, добавляетеpagination: {
el: '.clients__picture',
bulletClass: 'lol',
bulletActiveClass: 'active',
renderBullet: (index, className) => `<div class="${className}">${index + 1}</div>`,
},
For DOM trees which represent HTML documents, the returned tag name is always in the canonical upper-case form.
if(str.tagName == 'ul') {
} else if (str.tagName == 'li') {
str
, что за странный выбор имени? Там же элемент, а не строка.elem.append('li');
for (let el of strLi) { el.addEventListener('click',func); };
func
вынесено за пределы текущей функции, иначе бы при каждом клике всем существующим li
добавлялся новый обработчик.li
, на свежесозданных li
клик обрабатываться не будет (касается и тех, что изначально существуют).li
- так зачем назначать отдельный обработчик клика? То, что делаете в func
, вполне можно делать прямо тут.document.querySelector('ul').addEventListener('click', e => {
const t = e.target;
const ct = e.currentTarget;
t.insertAdjacentHTML('beforeend', ct === t ? '<li>text</li>' : '!');
});