const input = document.getElementById("search");
let searchdDebounceTimerHandler;
input.addEventListener("input", (e) => {
clearTimeout(searchdDebounceTimerHandler); // Если ввод быстрый, удаляем выполнение функции каждый раз
searchdDebounceTimerHandler = setTimeout(() => {
fetchSuggestions(e.target.value);
}, 1000); // Сработает через секунду от последнего нажатия
});
function debounce(func, delay) {
let timeoutId;
return function (...args) {
clearTimeout(timeoutId);
timeoutId = setTimeout(() => {
func.apply(this, args);
}, delay);
};
}
input.addEventListener('input', debounce(e => {
fetchSuggestions(e.target.value); // This is being called on every keystroke
}, 100));
a[0]
, а с result
.const getMin = arr => {
let result = arr[0];
for(i = 0; i < arr.length; i++){
if(arr[i] < result){
result = arr[i];
}
}
return result;
}
const getMinOld = a => {
let result = a[0];
for(i=0;i < a.length;i++){
if(a[i]< a[0]){
result = a[i];
}
}
return result;
}
let mas = [22,5,8,3,44,16];
console.log(getMin(mas)); // 3
console.log(getMinOld(mas)); // 16
Почему в большинстве рекомендаций и статей просто делают папку types и в нее уже все типы складывают?
Узнал через несколько дней что файлы с типами принято называть с окончанием .d.ts.
Разбираюсь в теме работы с токенами, не могуть понять, как должна работать авторизация по токенам. Если сервер нам присылает токены через Set-Cookie, мы не можем получить к ним доступ с помощью java script, но для дальнейших запросов нам нужно установить заголовок Authorization: `Bearer ${access_token}`
req.cookies
и при каждом запросе на сервер ты можешь сделать middleware проверка токена Хотелось бы увидеть пример. Версия nuxt - 2.n.
<input
type="text"
name="token"
inputmode="numeric"
pattern="[0-9]"
autocomplete="one-time-code"
/>