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)];
}
class PostApi {
static fetch() {
return fetch(BASE_URL, {method: 'get'}).then(res => res.json())
}
}
class PostApi {
static fetch() {
fetch(BASE_URL, {method: 'get'}).then(res => res.json())
}
}