Таймер выполняется в конце работы цикла?Нет. Он инициируется в цикле, а каллбэк ставит в очередь выполнения через секунду после инициации.
Знаю что нужно использовать async awaitasync/await не рекомендуется использовать в цикле. Лучше переписать функцию с использованием setInterval.
function lightWindow() {
const numLight = [1, 3, 5, 7, 11];
const houseLight = [3, 5, 11];
const lights = numLight.filter((el) => houseLight.includes(el));
if (lights.length === 0) {
return;
}
let idx = 0;
const timer = setInterval(
() => {
console.log(lights[idx]);
idx += 1;
if (idx >= lights.length) {
clearInterval(timer);
}
},
1000,
);
}
lightWindow();
const littleN = (arr, N) => arr.reduce(
(acc, cur) => {
const idx = acc.findIndex((el) => el.distance > cur.distance);
if (idx !== -1) {
acc.pop();
acc.splice(idx, 0, cur);
}
return acc;
},
Array(N).fill(arr[0])
);
If escape strings are not already part of your pattern you can add them using String.replace:
function escapeRegExp(string) { return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string }
const div = document.createElement('div');
[
['text', 'name', 'Введите имя'],
['text', 'phone', 'Введите номер телефона'],
['email', 'email', 'Введите адрес электронной почты'],
].forEach((d) => {
const input = document.createElement('input');
[input.type, input.name, input.placeholder] = d;
div.appendChild(e);
}
// ...
document.body.appendChild(div);