const escapeRegExp = (str) => str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
const findRegExp = new RegExp(escapeRegExp(find), 'i');
const index = arr.findIndex((name) => findRegExp.test(name));
function promiseRace(promises) {
let arr = [];
for (const elem of promises) {
elem
}
return arr[0]
}
console.log(promiseRace([firstPromise, thirdPromise, secondPromise])) // undefined
.then(() => {
arr.push(elem)
})
.then(() => {
arr.push(elem)
})
.then(() => {
arr.push(elem)
})
const allArr = [...arr1, ...(arr2 || []), ...(arr3 || [])];
window.scrollY
и window.scrollX
указывает на положение левого верхнего угла экрана. А он, при прокрутке до конца вниз, будет равен scrollHeight - clientHeight
. const allParams = elements.map(({ params }) => params);
// or
elements.forEach(({ params: { coup, x, y }) => { ... });
const uniqIds = new Set();
const result = exampleArray.filter(({ id }) => {
if (uniqIds.has(id)) {
return false;
}
uniqIds.add(id);
return true;
});
onChange
был андефайнд
.const Input = ({ title, type, onNameChange }) => (
<label>
<p>{title}</p>
<input onChange={onNameChange} type={type} />
</label>
)
const getLevel = (str, level) => {
const breckets = [...str.matchAll(/[()]/g)];
let currentLevel = 0;
let startLevelIndex = 0;
const results = [];
breckets.forEach((b) => {
if(b[0] === '(') {
currentLevel++;
if(currentLevel === level) {
startLevelIndex = b.index + 1;
}
return;
}
if(currentLevel === level) {
results.push(str.slice(startLevelIndex, b.index));
}
currentLevel--;
});
return results;
}
const testStr = '0 + (1 + 1 + (2 + (3 + 3 + (4 + 4) + 3) + 2 + (3 + (4 + 4 + 4) + (4 + (5 + 5) + 4) + 3) + 2) + 1) + 0 + (1 + 1)';
getLevel(testStr, 4);
player.x < enemy.x + enemy.w && player.x + player.w > enemy.x
&& player.y < enemy.y + enemy.h && player.y + player.h > enemy.y