fetch
есть своя обработка ошибок async function getRequest(url) {
let response = await fetch(url);
return await response.json().catch((err) => new Error(errorFunc(response.status)));
}
async function getJson(url) {
let json = await getRequest(url).catch((err) => console.log(err));
okFunc(json);
}
function chained(functions) {
return function(input) {
for (let i = 0; i < functions.length; i++) {
input = functions[i](input);
}
return input;
}
}
return
забыли, поэтому и undefined
items.sort((a, b) => {
if (a.rating === b.rating) return b.date - a.date;
else return b.rating - a.rating;
});
'photo100172_166443618,photo85635407_165186811'
let once = (func) => {
let counter = 0;
let result;
let error;
return function(...args) {
if (error) {
throw error;
}
if (counter > 0) {
return result;
}
try {
counter++;
return result = func(...args);
} catch (e) {
throw error = e;
}
}
}
let incOnce = once((a) => a + 1);
incOnce(42); // 43
incOnce(77); // 43
let errOnce = once((a) => {
if (a == 1) {
throw new Error('a');
}
});
errOnce(1); // Error
errOnce(2); // Error
var randomLetter = alhpabet[Math.floor(Math.random() * alhpabet.length)];
while (randomString.length < 6) {
randomString += alhpabet[Math.floor(Math.random() * alhpabet.length)];
}