const arr3 = arr1.map(n => (arr2.find(m => m.date === n) || { count: null }).count);
const obj = arr2.reduce((acc, n) => (acc[n.date] = n.count, acc), {});
const arr3 = arr1.map(n => obj[n] || null);
const arr3 = arr1.map(function(n) {
return this.get(n) || null;
}, new Map(arr2.map(n => [ n.date, n.count ])));
const statusArray = object.map(item => {
const opts = {
maxResults: 5,
key: users[2].token,
};
return new Promise((resolve, reject) => {
search(item.title, opts, (err, videos) => {
if (err) {
throw err;
}
item.youtubeId.new = videos[0].id;
item.videos = videos;
resolve(ArticleController.addArticle(item));
});
});
});
const parent = document.querySelector('ul');
const className = 'elem';
const count = 2;
for (const n of [].slice.call(parent.children, -count)) {
n.classList.remove(className);
}
// или
parent
.querySelectorAll(`.${className}:nth-last-child(-n + ${count})`)
.forEach(n => n.classList.remove(className));
// или
for (
let i = 0, el = parent.lastElementChild;
i < count && el;
i++, el = el.previousElementSibling
) {
el.classList.remove(className);
}
$('.one .qwer').css('font-size', i => `${12 + i * 4}px`);
document.querySelectorAll('.one .qwer').forEach((n, i) => {
n.style.fontSize = (-~-~-~i << 2) + 'px';
});
const items = document.querySelectorAll('.one .qwer');
for (let i = 0, j = 12; i < items.length; i++, j += 4) {
items[i].style.setProperty('font-size', ''.concat(j, 'px'));
}
const getTableData = ({ rows: [ head, ...rows ] }) =>
rows.map(function({ cells: c }) {
return this.reduce((obj, key, i) => (
obj[key] = c[i].innerText,
obj
), {});
}, Array.from(head.cells, n => n.innerText));
const tableData = getTableData(document.querySelector('table'));
const selector = '.active';
.const $result = $(selector).nextAll().addBack();
// или
const result = document.querySelectorAll(`${selector}, ${selector} ~ *`);
// или
const result = [];
for (
let el = document.querySelector(selector);
el;
el = el.nextElementSibling
) {
result.push(el);
}
// или
const el = document.querySelector(selector);
const siblings = el ? [...el.parentNode.children] : [];
const result = siblings.slice(siblings.indexOf(el));
$('select').each(function() {
$(this).select2({
minimumResultsForSearch: Infinity,
dropdownParent: $(this).closest('.card-more'),
});
});
$(this).prev(value).html(this.value);
$(this).prev(value).find('.range-slider__value').html(this.value);
$('select').select2({
minimumResultsForSearch: Infinity,
dropdownParent: $('.card-more'),
});
const $li = $('ul li').show().slice(8).hide();
$('#loadMore').on('click', function(e) {
e.preventDefault();
$li.fadeToggle();
});
get-age
- это не data-атрибут. Меняйте на data-age
.age_3_6
будет .age_3_6
, вместо age_7_10
будет .age_7_10
и т.д., ну а у элемента "все" будет data-age="*"
.const itemSelector = '.ped_holder .ped';
const buttonSelector = '.ages a';
const activeButtonClass = 'active';
const selectorAttr = 'age';
const $buttons = $(buttonSelector).click(function() {
const selector = $buttons
.removeClass(activeButtonClass)
.filter(this)
.addClass(activeButtonClass)
.data(selectorAttr);
$(itemSelector).hide().filter(selector).show();
});
// или, к чёрту jquery
const buttons = document.querySelectorAll(buttonSelector);
const items = document.querySelectorAll(itemSelector);
buttons.forEach(n => n.addEventListener('click', onClick));
function onClick({ target: t }) {
const selector = t.dataset[selectorAttr];
buttons.forEach(n => n.classList.toggle(activeButtonClass, n === t));
items.forEach(n => n.style.display = n.matches(selector) ? '' : 'none');
}
arr.sort((a, b) => {
a = a.split('.', 2);
b = b.split('.', 2);
return (a[1] - b[1]) || (a[0] - b[0]);
});
const sortedArr = arr
.map(n => n.split('.'))
.sort((a, b) => (a[1] - b[1]) || (a[0] - b[0]))
.map(n => n.join('.'));