function foo(...args) {
console.log(args[N]);
}
function foo() {
console.log(arguments[N]);
}
function foo(...{ [N]: x }) {
console.log(x);
}
const cards = Array.from(
document.querySelectorAll('[data-component="card"]'),
n => new Card(n)
);
constructor(el) {
if (typeof el === 'string') {
return Array.from(document.querySelectorAll(el), n => new Card(n));
}
// дальше всё по-старому
const cards = new Card('[data-component="card"]');
Подозреваю, что виноват ".parents()"
.closest('.block')
или .parent().next('.slider-btns')
. <input type="text" value="0.00">
document.querySelector('input').addEventListener('keypress', function(e) {
e.preventDefault();
this.value = this.value.replace(/(0)(?!.*\1)/, e.key);
});
const index = arr.findIndex(n => n.id === id);
if (index !== -1) {
arr.splice(index, 1);
}
const newArr = arr.filter(n => n.id !== id);
for (let i = arr.length; i--;) {
if (arr[i].id === id) {
arr.splice(i, 1);
}
}
reduceRight
используется не совсем по назначения, как и оператор &&
):arr.reduceRight((_, n, i, a) => n.id === id && a.splice(i, 1), null);
let countDeleted = 0;
for (let i = 0; i < arr.length; i++) {
arr[i - countDeleted] = arr[i];
countDeleted += arr[i].id === id;
}
arr.length -= countDeleted;
arr.splice(0, arr.length, ...arr.filter(n => n.id !== id));
<input type="range" min="20" max="200" value="100">
<img src="...">
document.querySelector('input').addEventListener('input', function() {
document.querySelector('img').style.filter = `brightness(${this.value}%)`;
});
$('.box').each((i, n) => {
const $blocks = $('.section .block', n);
$('.imgs img', n).each((i, n) => $blocks.eq(i).append(n));
});
document.querySelectorAll('.box').forEach(n => {
const images = n.querySelectorAll('img');
n.querySelectorAll('.block').forEach((n, i) => n.append(images[i]));
});
return this.data();
const chunked = (data, chunkSize) =>
Array.prototype.reduce.call(
data,
(acc, n, i) => (
i = i / chunkSize | 0,
(acc[i] = acc[i] || []).push(n),
acc
),
[]
);
console.log(chunked([...Array(10).keys()], 3));
console.log(chunked('ABCDEFG', 2));
console.log(chunked(document.querySelectorAll('img'), 5));
for (let i = 0; i < answer.length - 1; i++)
for (let i = 0; i < words.length; i++)
p.style.color = colors[i]
. function throttle(f, delay) {
let lastCall = -Infinity;
return function() {
const now = +new Date;
if (now - lastCall > delay) {
lastCall = now;
return f.apply(this, arguments);
}
};
}
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();