arr.reduce((acc, n) => ((acc[n.room] = acc[n.room] || []).push(n), acc), {})
<v-col v-for="item of components_list" v-bind:key="item.id">
<v-text-field
v-bind="getProps(item)"
v-model="components[item.code_name]"
/>
</v-col>
где getProps
возвращает объект вида { [prop]: value }
. let $body = document.querySelector('body');
let $bodyH = $body.clientHeight;
let $bodyW = $body.clientWidth;
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
async function main() {
let ask = prompt('How many circles you want to draw?');
if (ask !== null || ask !== '') {
for (let i = 0; i < ask; i++) {
drowCircle(i);
await sleep(1000);
}
}
}
main();
function drowCircle(i) {
let $circle = document.createElement('div');
let $circleSize = getRand(50, 100);
let positionX = getRand(0, $bodyW - $circleSize);
let positionY = getRand(0, $bodyH - $circleSize);
$body.insertAdjacentElement('afterbegin', $circle);
$circle.style.width = $circle.style.height = `${$circleSize}px`;
$circle.style.zIndex = i+1;
$circle.style.backgroundColor = `rgb(${getRand(0,255)},${getRand(0,255)},${getRand(0,255)})`;
$circle.style.borderRadius = '50%';
$circle.style.position = 'absolute';
$circle.style.top = `${positionY}px`;
$circle.style.left = `${positionX}px`;
}
function getRand(min, max) {
let rand = min - 0.5 + Math.random() * (max - min + 1);
return Math.round(rand);
}
/**
* асинхрота с запросом. Возвращает Promise
*/
const doAsyncStuff = (urlIter, urlSite) => new Promise((resolve, reject) => {
needle.get(urlIter, (err, result) => { // Сама асинхронная функция
if (err) reject(err);
$('.product-card__link')
.each((i, val) => prodLink.push(urlSite + $(val).attr("href")));
resolve();
})
})
/**
* Тот самый цикл
* @param {number} quanPage число страниц
*/
const doStuff = async quanPage => {
for(let i = 1; i <= quanPage; i++) {
let urlIter = urlSite + i; // Ссылка, которая создается с каждой новой итерацией
await doAsyncStuff(urlIter, urlSite); // Ждём-с!
}
}
doStuff(10);
i = 1;
function ciklotron() {
if (i <= quanPage) {
let urlIter = urlSite + i;
needle.get(urlIter, function (err, res) {
if (err) throw (err);
prodUrl = $('.product-card__link');
prodUrl.each(function (i, val) {
prodLink.push(urlSite + $(val).attr("href"));
});
i = Number(i) + Number(1); // Увелчиваем счетчик на еденицу
ciklotron(); // Вызываем сами себя
});
}
}
arr.map((n, i) => n.repeat(i + 1))
arr.map((n, i) => Array(i + 1).fill(n).join(''))
arr.map((n, i) => Array(i + 2).join(n))
const getDayName = (number, lang) => ({
en: [ 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday' ],
ru: [ 'Воскресенье', 'Понедельник', 'Вторник', 'Среда', 'Четверг', 'Пятница', 'Суббота' ],
})[lang][number % 7];
console.log(getDayName(5, 'en')) // Friday
console.log(getDayName(7, 'ru')) // Воскресенье