я что-то не так делаю видно
const a = v1 => {
const f = v2 => a(v1 + v2);
f.valueOf = () => v1;
return f;
};
a(1)(2)(3)(4)(5) * 6 // 90
10 + a(4)(5)(6) // 25
Math.pow(a(8)(1), 3) // 729
a(4)(6) - a(3) // 7
Переписал код с ES5 на ES6
const adjacentElementsProduct = arr => arr
.sort((a, b) => a - b)
.slice(-2)
.reduce((acc, n) => acc * n, 1);
arr = arr.filter(n => n.id !== ID);
arr.splice(arr.findIndex(n => n.id === ID), 1);
const index = arr.findIndex(n => n.id === ID);
if (index !== -1) {
arr.splice(index, 1);
}
function toggleClass(selector, className, delay) {
let index = -1;
return setInterval($items => {
$items.eq(index).removeClass(className);
index = (index + 1) % $items.length;
$items.eq(index).addClass(className);
}, delay, $(selector));
}
const intervalId = toggleClass('.wrap div', 'active', 300);
function toggleClass(selector, className, delay) {
const items = document.querySelectorAll(selector);
let index = ~-items.length;
return items.length
? setInterval(() => {
items[index].classList.remove(className);
index = -~index % items.length;
items[index].classList.add(className);
}, delay)
: null;
}
document.querySelectorAll('.item-parent').forEach(n => {
n.insertAdjacentHTML('beforeend', '<div class="item-decor"></div>');
});
for (const n of document.getElementsByClassName('item-parent')) {
const div = document.createElement('div');
div.classList.add('item-decor');
n.appendChild(div);
}
const $sorted = $('table tr').sort(el => $(el).hasClass('important') ? -1 : 1);
$sorted.appendTo($sorted.parent());
const $important = $('table tr.important');
$important.parent().prepend($important);
const $el = $('[data-value]');
// или
const el = document.querySelector('[data-value]');
const str = $el.data('value');
// или
const str = $el.attr('data-value');
// или
const str = el.dataset.value;
// или
const str = el.getAttribute('data-value');
// или
const str = el.attributes['data-value'].value;
const arr = str.split(',');
// или
const arr = str.match(/\d+/g) || [];
// или
const arr = str.split(/\D/);
// или
const arr = JSON.parse(`[${str}]`); // вместо строк тут будут числа
// или
const arr = eval('[' + str + ']'); // и тут тоже числа
.modal-close
не нужен - его убираем; добавляем проверку, кем является целевой элемент:$('.modal-window').click(function(e) {
if (e.target.matches('.modal-window, .modal-close')) {
$(this).hide();
}
});
const container = document.querySelector('.dots-wrapper');
const tag = 'div';
const className = 'dot';
const count = 10;
const elementHTML = `<${tag} class="${className}"></${tag}>`;
const elementsHTML = Array(count).fill(elementHTML).join('');
// или
const elementsHTML = Array(count + 1).join(elementHTML);
// или
const elementsHTML = elementHTML.repeat(count);
container.innerHTML = elementsHTML;
// или
container.insertAdjacentHTML('beforeend', elementsHTML);
for (let i = 0; i < count; i++) {
const element = document.createElement(tag);
element.classList.value = className;
container.insertAdjacentElement('beforeend', element);
}
while (container.children.length < count) {
const element = document.createElement(tag);
element.classList.add(className);
container.appendChild(element);
}
const element = document.createElement(tag);
element.className = className;
container.append(...Array.from({ length: count }, () => element.cloneNode()));
<div class="app">
<div class="plain"></div>
</div>
.app {
width: 200px;
height: 200px;
overflow: scroll;
}
.plain {
width: 1000px;
height: 1000px;
background: linear-gradient(135deg, red, blue);
}
let x = null;
let y = null;
document.querySelector('.app').addEventListener('mousemove', function(e) {
if (e.buttons) {
if (typeof x === 'number') {
this.scrollLeft += (x - e.layerX) * 3;
this.scrollTop += (y - e.layerY) * 3;
}
x = e.layerX;
y = e.layerY;
} else {
x = y = null;
}
});
setTimeout(function() {
console.log(this.resorts.join(', '));
}.bind(this), delay);
var that = this;
setTimeout(function() {
console.log(that.resorts.join(', '));
}, delay);
<button data-block="block-one">69</button>
<button data-block="block-two">187</button>
<button data-block="block-three">666</button>
<div class="block block-one">hello, world!!</div>
<div class="block block-two">fuck the world</div>
<div class="block block-three">fuck everything</div>
$('body').on('click', 'button', function() {
const $block = $(`.${this.dataset.block}`).toggleClass('show');
$('.block').not($block).removeClass('show');
});
// или
document.addEventListener('click', ({ target: { dataset: { block } } }) => {
if (block) {
document.querySelectorAll('.block').forEach(({ classList: cl }) => {
cl[cl.contains(block) ? 'toggle' : 'remove']('show');
});
}
});
<button class="button">69</button>
<button class="button">187</button>
<button class="button">666</button>
<div class="block block-one">hello, world!!</div>
<div class="block block-two">fuck the world</div>
<div class="block block-three">fuck everything</div>
const $blocks = $('.block');
const $buttons = $('.button').click(function() {
const $block = $blocks.eq($buttons.index(this)).toggleClass('show');
$blocks.not($block).removeClass('show');
});
// или
const blocks = document.querySelectorAll('.block');
const buttons = document.querySelectorAll('.button');
buttons.forEach(n => n.addEventListener('click', onClick));
function onClick() {
const index = Array.prototype.indexOf.call(buttons, this);
blocks.forEach((n, i) => n.classList[i === index ? 'toggle' : 'remove']('show'));
}