const keys = [ 'id', 'secondId' ];
const result = firstArray.map(n => secondArray.find(m => keys.every(k => n[k] === m[k])) ?? n);
const arrToTree = (arr, keys) =>
arr.reduce((acc, n) => (
keys.reduce((p, c, i) => p[n[c]] ??= i + 1 === keys.length ? n : {}, acc),
acc
), {});
const keys = [ 'id', 'secondId' ];
const tree = arrToTree(secondArray, keys);
const result = firstArray.map(n => keys.reduce((p, c) => p?.[n[c]], tree) ?? n);
const arrToTree = (arr, keys) =>
arr.reduce((acc, n) => (
keys(n).reduce(
(p, c, i, a) => p.set(c, p.get(c) ?? (-~i === a.length ? n : new Map)).get(c),
acc
),
acc
), new Map);
const keys = n => [ n.id, n.secondId ];
const result = firstArray.map(function(n) {
return keys(n).reduce((p, c) => p?.get(c), this) ?? n;
}, arrToTree(secondArray, keys));
const timeFromBackend = "2022-11-15T20:00:00Z";
const localTime = new Date(timeFromBackend); // 23:00 Msk
const oo = n => n.toString(10).padStart(2, '0');
const YYYY = localTime.getFullYear();
const MM = oo(localTime.getMonth() + 1);
const DD = oo(localTime.getDate());
const HH = oo(localTime.getHours());
const II = oo(localTime.getMinutes());
const localTimeForInput = [YYYY, MM, DD].join('-') + 'T' + [HH, II].join(':');
console.log(localTimeForInput); // 2022-11-15T23:00
const timeFromBackend = "2022-11-15T20:00:00Z";
const localTime = new Date(timeFromBackend); // 23:00 Msk
const shiftedTime = new Date(localTime);
shiftedTime.setMinutes(shiftedTime.getMinutes() - shiftedTime.getTimezoneOffset());
const timeForInput = shiftedTime.toISOString().substring(0, 16);
console.log(timeForInput); // "2022-11-15T23:00"
const timeFromInput = "2022-11-15T22:00";
const date = new Date(timeFromInput);
const timeForBackend = date.toISOString().substring(0, 19) + 'Z';
console.log(timeForBackend) // "2022-11-15T19:00:00Z"
var text = 'Привет, мир!';
var u8a = new TextEncoder().encode(text);
var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
var bytes = u8a, i, len = bytes.length, base64 = '';
for (i = 0; i < len; i += 3) {
base64 += chars[bytes[i] >> 2];
base64 += chars[((bytes[i] & 3) << 4) | (bytes[i + 1] >> 4)];
base64 += chars[((bytes[i + 1] & 15) << 2) | (bytes[i + 2] >> 6)];
base64 += chars[bytes[i + 2] & 63];
}
if (len % 3 === 2) {
base64 = base64.substring(0, base64.length - 1) + '=';
}
else if (len % 3 === 1) {
base64 = base64.substring(0, base64.length - 2) + '==';
}
console.log(base64);
var text = 'Привет, мир!';
var blob = new Blob([ text ]);
var reader = new FileReader();
reader.readAsDataURL(blob);
reader.onload = function() {
var base64 = reader.result.split(',')[1];
console.log(base64);
};
const currentYear = new Date().getFullYear();
const years = [];
for (let year = currentYear - 5; year <= currentYear + 5; year++) {
years.push(year);
}
years // [2017, 2018, 2019, 2020, 2021, 2022, 2023, 2024, 2025, 2026, 2027]
for (let i = 0; i < 5; i++) {
let newYear = year; // <--- тут ошибка
firstYears.push((newYear -= 1));
}
handleChangeInfoMain: (value: string) => void