JavaScript RegExp objects are stateful when they have the global or sticky flags set (e.g., /foo/g or /foo/y). They store a lastIndex from the previous match. Using this internally, test() can be used to iterate over multiple matches in a string of text (with capture groups).Кратко - с опциями g и y объект RegExp сохраняет позицию, с которой продолжает поиск при следующем вызове. У вас одинаковые строки и второй вызов начинает с позиции, на которой закончился первый вызов, то есть уже после '.mp3'.
countCookies(3, 6, [0, 0, 0]); // 1
countCookies(3, 2, [0, 2, 2]); // 0
- const allCookies = cookies.reduce((sum, acc) => sum + acc, 0);
- let maxCookies = Number(Math.max.apply(null, cookies));
+ const maxCookies = Math.max(...cookies);
- let sum = cookies.reduce((acc, c) => acc + Math.floor((c + K - 1) / K), 0);
+ const sum = cookies.reduce((acc, c) => acc + Math.ceil(c / K), 0);
$("#address").suggestions(...)
, то плагин навешивает на элемент свои скрипты и, возможно, дополнительные элементы DOM. А уже в этих скриптах по событию onSelect вызывается каллбэк-функция, в которую передаётся suggestion.header.classList.remove("fixed-header");
const aheader = document.querySelector(".fixed-header");
получаете null.- if (window.scrollY > 100) {
- aheader.classList.add("active-header");
- } else {
- aheader.classList.remove("active-header");
- }
+ aheader?.classList.toggle('active-header', window.scrollY > 100);
catch(onRejected)
Returns a new Promise. This new promise is always pending when returned, regardless of the current promise's status. It's eventually rejected if onRejected throws an error or returns a Promise which is itself rejected; otherwise, it's eventually fulfilled.
.catch(null)
не работает, поскольку не указана функция onRejected..catch
возвращает Promise.fulfilled, согласно спецификации.