const boxes = document.querySelectorAll('.box');
const isNested = (f, t, c) => c + 1 >= f && c + 1 <= t;
const insertAfter = (elem, refElem) => refElem.parentNode.insertBefore(elem, refElem.nextSibling);
const transferBoxesToWrapper = (fromIndex, toIndex, wrapper) => {
boxes.forEach((box, i) => isNested(fromIndex, toIndex, i) && wrapper.appendChild(box));
}
const createWrapper = (fromIndex, toIndex) => {
let wrapper = document.createElement('div');
wrapper.classList.add('wrapper');
insertAfter(wrapper, boxes[fromIndex - 1]);
transferBoxesToWrapper(fromIndex, toIndex, wrapper);
}
createWrapper(3, 5);
let str = 'текст';
//...
if (str === 'текст') {
document.write(str);
} else {
//Делаем что-то другое
}
npm uninstall -g create-react-app
npm install create-react-app
'area' || 'base' || 'col' || 'command'
, получается у вас всегда проверяется if (els[i].tagName.toLowerCase() === 'area') { return; }
const values = ['area', 'base', 'col', 'command'];
if (values.includes(els[i].tagName.toLowerCase())) {
return;
}
this.sendData = this.sendData.bind(this);
const getPairsWithSumFromArr = (arr, sum) => {
let map = {},
res = [];
for (let i=0; i < arr.length; i++) {
const currEl = arr[i];
if (map[currEl] !== undefined) {
res.push([map[currEl], currEl]);
} else {
map[sum - currEl] = currEl;
}
}
return res;
}
window.onscroll = function(ev) {
if ((window.innerHeight + window.pageYOffset) >= document.body.offsetHeight) {
//доскролил
}
};
var lastScrollTop = 0;
window.addEventListener("scroll", function(){
var st = window.pageYOffset || document.documentElement.scrollTop;
if (st > lastScrollTop){
// скролит вниз
} else {
// скролит вверх
}
lastScrollTop = st <= 0 ? 0 : st;
}, false);
state: { hadSubmitted: false, };
componentDidUpdate(prevProps, prevState) {
const { hadSubmitted } = this.state;
if (hadSubmitted) {
//...validate
}
}
handleSubmit(e) {
...
this.setState({
hadSubmitted: true,
});
}
validate(state, form) {
...
this.setState({ hadSubmitted: false, })
}