Я плохой программист
или же неправильно распределяю время на программирование?(от 1,5 часов до 5 в день) в чем проблема?
Я надеюсь вы разрешите мой вопрос и дадите мне какой либо ответ, благодарю тех кто напишет адекватный ответ, а тех кто будет писать откровенные гадости, дабы поднять свое эго мне просто жалко.
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
When bash is invoked as an interactive login shell, or as a non-interactive shell with the --login option, it first reads and executes commands from the file /etc/profile, if that file exists. After reading that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order, and reads and executes commands from the first one that exists and is readable. The --noprofile
option may be used when the shell is started to inhibit this behavior.
When an interactive shell that is not a login shell is started, bash reads and executes commands from ~/.bashrc, if that file exists. This may be inhibited by using the --norc option. The --rcfile
file option will force bash to read and execute commands from file instead of ~/.bashrc.
from collections import Counter
a = [{'id': '1', 'qty': 6}, {'id': '2', 'qty': 1}, {'id': '1', 'qty': 1}, {'id': '2', 'qty': 1}, {'id': '3', 'qty': 10}, {'id': '1', 'qty': 1}]
c = sum((Counter({d['id']: d['qty']}) for d in a), Counter())
result = [dict(id=k, qty=v) for k, v in c.items()]
const index = вам виднее, что тут должно быть;
const className = 'header';
const selector = `.${className}`;
const key = 'id';
const attr = `data-${key}`;
const parentSelector = 'table tbody';
):const $elements = $(parentSelector).children();
const $el = $elements.eq(Math.min(index, $elements.length - 1));
const val = ($el.is(selector) ? $el : $el.prev(selector)).attr(attr) ?? null;
// или
const elements = document.querySelector(parentSelector).children;
let val = null;
for (let i = Math.min(index, ~-elements.length); i >= 0; i--) {
if (elements[i].matches(selector)) {
val = elements[i].getAttribute(attr);
break;
}
}
const elementsSelector = 'table tr';
) разные (конкретно в вашем случае это могла бы быть таблица с несколькими tbody
):const val = $(elementsSelector)
.slice(0, index + 1)
.filter(selector)
.last()
.data(key) ?? null;
// или (UPD. На момент публикации вопроса метод findLast отсутствовал,
// вместо него использовалась связка из reverse-find)
const { [key]: val = null } = Array
.from(document.querySelectorAll(elementsSelector))
.slice(0, -~index)
.findLast(n => n.classList.contains(className))
?.dataset ?? {};