const today = String((new Date()).getDate()).padStart(2, '0');
const dayStartElements = document.querySelectorAll(".js-text");
dayStartElements.forEach((el) => { el.innerText = `${dd}` });
If the handler throws an error or returns a rejected promise, the promise returned by finally() will be rejected with that value instead. Otherwise, the return value of the handler does not affect the state of the original promise.
...
UnlikePromise.resolve(2).then(() => 77, () => {})
(which will return a resolved promise with the result 77),Promise.resolve(2).finally(() => 77)
will return a new resolved promise with the result 2.
Similarly, unlikePromise.reject(3).then(() => {}, () => 88)
(which will return a resolved promise with the value 88),Promise.reject(3).finally(() => 88)
will return a rejected promise with the reason 3.
But, bothPromise.reject(3).finally(() => {throw 99})
andwill reject the returned promise with the reason 99.Promise.reject(3).finally(() => Promise.reject(99))
function find(sum, n, m) {
if (n === 1) {
return [`${sum}`];
}
const result = [];
const min = Math.max(m, Math.floor(sum - (n - 1) * 9));
const max = Math.floor(sum / n);
for (let i = min; i <= max; i += 1) {
find(sum - i, n - 1, i).forEach((el) => result.push(`${i}${el}`));
}
return result;
}
function findAll(sum, n) {
if (sum > n * 9 || sum < n) {
return [];
}
const result = find(sum, n, 1);
return [result.length, result[0], result.pop()];
}
0x89 0x50 0x4e 0x47 0x0d 0x0a 0x1a 0x0a
или\x89PNG\r\n\x1a\n
const isLetter = (c) => {
if (c === '_' || c === '$') {
return false;
}
try {
eval(`let ${c};`);
return true;
} catch (e) {
return false;
}
}
const isUpperCase = (c) => c === c.toUpperCase();
const convertText = (string) => {
for (let i = 0; i < string.length; i += 1) {
if (isLetter(string[i])) {
return isUpperCase(string[i]) ? string : reverse(string);
}
}
return reverse(string);
}
const isLetter = (c) => /\p{L}/u.test(c);
const isUpperCase = (c) => /\p{Lu}/u.test(c);
const movingAverage = (data, windowSize) => {
let sum = data.slice(0, windowSize).reduce((acc, cur) => acc + cur, 0);
const result = [sum / windowSize];
for (let i = windowSize; i < data.length; i += 1) {
sum = sum - data[i - windowSize] + data[i];
result.push(sum / windowSize);
}
return result;
};
console.log(movingAverage([9, 3, 2, 0, 1, 5, 1, 0, 0], 3));
// Array(7) [ 4.666666666666667, 1.6666666666666667, 1, 2, 2.3333333333333335, 2, 0.3333333333333333 ]
const StringChallenge = (str) =>
str.replaceAll(/(?<=[13579])(?=[13579])/g, '-')
.replaceAll(/(?<=[2468])(?=[2468])/g, '*');
const StringChallenge = (str) =>
str.split('').reduce(
(acc, dig) => {
const sign = +dig ? (dig % 2 ? '-' : '*') : '';
return {
str: acc.str + (acc.sign === sign ? sign : '') + dig,
sign,
};
},
{ str: '', sign: '' },
).str;