async function foo(val = 0) {
const response = await request(val); //предполагается, что request возвращает promise
if (response.error) throw new Error('something bad happened');
//делаем что-то с response
foo(response.newVal); //вызываем foo с новым val
}
<sup></sup>
всегда находится вначале, то достаточно этого:const str = 'Travel <sup style="color:#000;" data-footnote-merchant="1676" data-footnote-index="0" class="sup-comment comm_125">125</sup>Rewards 3000 Loyalty Good and Excellent Credit';
const res = str.replace(/\d+(?!.*<\/sup>)/g, '<span>$&<\/span>');
const str = 'Travel <sup style="color:#000;" data-footnote-merchant="1676" data-footnote-index="0" class="sup-comment comm_125">125</sup>Rewards 3000 Loyalty Good and Excellent 500 Credit <sup style="color:#000;" data-footnote-merchant="1676" data-footnote-index="0" class="sup-comment comm_125">666</sup> <sup>000</sup> Good and Excellent 666';
const res = str.replace(/<sup.*?>.*?<\/sup>|(\d+)/g, (m, p1) => p1 ? `<span>${p1}<\/span>` : m);
search_null() {
this.search = this.search.replace(RegExp(this.brands.map(o => o.name).join('|'), 'gi'), ' ');
}
const foo = (function(x) {
console.log(x);
}).bind(null, 666);
foo(); //666
const arr = [...Array(100)].map((_, i) => i + 1);
const res = arr.map(n => `${n % 3 ? '' : 'Foo'}${n % 5 ? '' : 'Bar'}` || n);
const resp = [
{
day: 'Понедельник',
start_time: '18:00',
end_time: '21:00'
},
{
day: 'Вторник',
start_time: '18:00',
end_time: '21:00'
},
{
day: 'Среда',
start_time: '18:00',
end_time: '21:00'
},
{
day: 'Четверг',
start_time: '17:30',
end_time: '21:00'
},
{
day: 'Пятница',
start_time: '12:30',
end_time: '21:00'
},
{
day: 'Суббота',
start_time: '18:00',
end_time: '21:00'
},
{
day: 'Воскресенье',
start_time: '18:00',
end_time: '21:00'
}
];
const days = resp.reduce((a, c, i) => {
if (!i || a[a.length - 1].start_time != c.start_time || a[a.length - 1].end_time != c.end_time) {
a.push({...c});
} else {
a[a.length - 1].day = a[a.length - 1].day.split('-')[0] + `-${c.day}`;
}
return a;
}, []).map(o => `${o.day}, с ${o.start_time} до ${o.end_time}`).join('\n');
/* Понедельник-Среда, с 18:00 до 21:00
Четверг, с 17:30 до 21:00
Пятница, с 12:30 до 21:00
Суббота-Воскресенье, с 18:00 до 21:00 */
function makeRed() {
document.querySelectorAll('p').forEach(el => el.style.backgroundColor = 'red');
}
chrome.storage.local.set({[name]: data});
Object.entries(obj).reduce((a, [k, v]) => {
const ss = k.slice(0, -1);
if (!a.ref[ss]) a.ref[ss] = k;
a.res[a.ref[ss]] = ~~a.res[a.ref[ss]] + v;
return a;
}, {ref: {}, res: {}}).res;