let getData = (attempts) => {
if (attempts < 1) {
return Promise.reject('Max attempts reached.');
}
return new Promise((res, rej) => {
console.log('Attempt to fetch data: #' + attempts);
attempts == 1
? setTimeout(() => {res('This is my data')}, 3000)
: setTimeout(() => {rej('Shit happens')}, 3000);
}).catch(e => {
return getData(attempts - 1);
})
}
getData(3)
.then(r => console.info('=> ' + r))
.catch(e => console.error(e));
const mazeCopy = JSON.parse(JSON.stringify(maze));
method adds a node to the end of the list of children of a specified parent node. If the given child is a reference to an existing node in the document, appendChild() moves it from its current position to the new position
const els = document.querySelectorAll('#mobilemenu li');
// Array.from().forEach() можно заменить на цикл for
// for (el of Array.prototype.slice.call(els) ) { ... }
Array
.from(els)
.forEach(el => { el.childElementCount === 0 ? el.remove() : 0; })