Object.entries(props).filter(n => n[1]).map(n => n[0]).join(',')
// или
`${Object.entries(props).reduce((acc, [ k, v ]) => (v && acc.push(k), acc), [])}`
// или
Object.entries(props).map(n => n[1] && n[0]).filter(Boolean).toString()
// или
'' + Object.keys(props).reduce((acc, n) => props[n] ? [ ...acc, n ] : acc, [])
// или
String(Object.keys(props).filter(n => props[n]))
const colors = [ 'red', 'lime', 'yellow', 'aqua', 'brown', 'magenta' ];
$('.item').css('background-color', i => colors[i % colors.length]);
// или
document.querySelectorAll('.item').forEach((n, i) => {
n.style.backgroundColor = colors[i % colors.length];
});
this.sliderPoint.on('click', e => {
this.currentImg = e.target.dataset.id;
this.scrollImages(this.currentImg, this.speed);
});
[...Array(count)].map((n, i) => `<div class="slider-point" data-id="${i}"></div>`).join('')
Array(count).fill('<div class="slider-point"></div>').join('')
this.currentImg = $(e.target).index();
document.addEventListener('click', e => {
const slide = e.target.closest('.slide');
if (slide) {
const index = Array.prototype.indexOf.call(
slide.parentNode.children,
slide
);
console.log(index);
}
});
for (const n of document.querySelectorAll('.slide')) {
n.addEventListener('click', onClick);
}
function onClick() {
let index = 0;
for (let el = this; el = el.previousElementSibling; index++) ;
console.log(index);
}
document.querySelectorAll('.slider').forEach(function({ children }) {
[].forEach.call(children, (n, i) => {
n.dataset.index = i;
n.addEventListener('click', this);
});
}, e => console.log(+e.currentTarget.dataset.index));
const slidesCount = this.slider.find('.slide').length;
// или
const { length: slidesCount } = this.slider.children();
const dotHTML = '<div class="slider-point"></div>';
const dotsHTML = Array(slidesCount).fill(dotHTML).join('');
// или
const dotsHTML = Array(slidesCount + 1).join(dotHTML);
// или
const dotsHTML = dotHTML.repeat(slidesCount);
this.slider.siblings('.slider-pagination').append(dotsHTML);
// или
this.slider.closest('.slider-box').find('.slider-pagination').html(dotsHTML);
this.previousImage = this.previousImage.bind(this);
this.nextImage = this.nextImage.bind(this);
this.prevBtn = this.slider.siblings(".slider-btn.previous");
this.nextBtn = this.slider.siblings(".slider-btn.next");
if($(this).children().is(':checked')){ $(this).addClass('active'); } else { $(this).removeClass('active'); }
$(this).addClass('active').siblings().removeClass('active');
const groupQuestions = arr => ({
testId: arr[0].testId,
questions: Object.values(arr.reduce((acc, n) => {
const id = n.questionId;
(acc[id] = acc[id] || {
questionId: id,
questionText: n.questionText,
answers: [],
}).answers.push({
answer: n.answer,
isRight: n.isRight,
});
return acc;
}, {})),
});
const data = [
{
floors: [ 1 ],
limits: [
{ f: 1.26, max: 120 },
{ f: 1.24, max: 140 },
{ f: 1.23, max: 160 },
{ f: 1.22, max: 200 },
{ f: 1.20, max: 260 },
{ f: 1.19, max: 300 },
],
},
{
floors: [ 2, 3 ],
limits: [
{ f: 1.00, max: 100, excludeMax: true },
{ f: 1.30, max: 130 },
{ f: 1.27, max: 160 },
{ f: 1.24, max: 200 },
{ f: 1.22, max: 300 },
],
},
];
const d = data.find(n => n.floors.includes(floors.value));
if (d) {
const v = area.value;
console.log((d.limits.find(n => n.excludeMax ? n.max > v : n.max >= v) || { f: 1 }).f);
}
const count1 = [
num => (('' + num).match(/1/g) || []).length,
num => num.toString().replace(/[^1]/g, '').length,
num => `${num}`.split('').filter(d => !~-d).length,
num => [...String(num)].reduce((s, d) => s + (d == 1), 0),
num => ''.split.call(num, 1).length - 1,
];
const numbers = [
23489,
-11,
-93481,
7211231,
0,
123.321,
Infinity,
NaN,
];
count1.map(f => numbers.filter(n => f(n) === 2)).forEach(n => console.log(n));
create: function() {
на create: function(e, ui) {
. document.querySelector('.nav__list').addEventListener('click', function(e) {
const sub = e.target.nextElementSibling;
if (sub && sub.classList.contains('nav__sublist')) {
sub.classList.toggle('nav--show');
}
});
for (const k in obj) {
obj[k] = Object.values(obj[k]);
}
const newObj = Object
.keys(obj)
.reduce((acc, k) => (acc[k] = Object.values(obj[k]), acc), {});
// или
const newObj = Object.fromEntries(Object
.entries(obj)
.map(n => [ n[0], Object.values(n[1]) ])
);
const ul = document.querySelector('#ul');
const button = document.querySelector('#but');
ul.addEventListener('click', function(e) {
if (e.target.tagName === 'LI') {
e.target.textContent += '!';
}
});
button.addEventListener('click', function() {
const li = document.createElement('li');
li.textContent = `пункт ${ul.children.length + 1}`;
ul.appendChild(li);
});
ul.addEventListener('click', ({ target: t }) => t.matches('li') && t.append('!'));
button.addEventListener('click', () => {
ul.insertAdjacentHTML('beforeend', `<li>пункт ${-~ul.children.length}</li>`);
});