строка = floor(индекс / количество столбцов)
столбец = индекс % количество столбцов
const result = Object.values(arr.reduce((acc, n) => {
const group = acc[n.id] = acc[n.id] || { id: n.id, offers: [] };
group.offers.push(n);
return acc;
}, {}));
function createTree(data) {
const tree = { null: { cat: {} } };
data.forEach(n => tree[n.id] = { cat: {}, ...n });
data.forEach(n => tree[n.parent].cat[n.name] = tree[n.id]);
return tree.null.cat;
}
success(data) {
document.querySelector('#result').innerHTML = Array
.from(data.querySelectorAll('info'), n => `<div>${n.firstChild.nodeValue}</div>`)
.join('');
},
document.getElementById('result').innerHTML = (xml
.match(/<info><!\[CDATA\[[^\]]*/g) || [])
.map(n => '<div>' + n.slice(15) + '</div>')
.join('');
Let shiftCount be the result of masking out all but the least significant 5 bits of rnum, that is, compute rnum & 0x1F.
const obj = (str
.match(/\w+=[\d;]+/g) || [])
.reduce((acc, n) => {
const [ key, values ] = n.split('=');
acc[key] = values.split(';').map(Number);
return acc;
}, {});
const obj = Array
.from(new URL(str).searchParams)
.reduce((acc, [ k, v ]) => (
acc[k] = v.split(';').map(n => +n),
acc
), {});
const elements = document.querySelectorAll('p');
const attrNamePrefix = 'bind:';
const result = Array.prototype.filter.call(
elements,
n => Array.prototype.some.call(
n.attributes,
m => m.name.startsWith(attrNamePrefix)
)
);
const result = [];
for (const n of elements) {
for (const m of n.attributes) {
if (m.name.indexOf(attrNamePrefix) === 0) {
result.push(n);
break;
}
}
}
<div class="counter">
<span class="counter__visible"></span> /
<span class="counter__total"></span>
</div>
$('.loadmore').on('click', function(e) {
e.preventDefault();
const $items = $('.item');
$items.filter(':hidden').slice(0, 4).fadeIn();
const visible = $items.filter(':visible').length;
$('.counter__visible').text(visible);
$('.counter__total').text($items.length);
if ($items.length === visible) {
$(this).fadeOut('slow');
}
}).click();
const defineQuestionDataByLanguage = (question, lang) => {
const answerLang = ({
2: 'swe',
// ещё какие-то языки, если надо
})[lang] || 'en';
return {
labelLang: question[answerLang],
answerLang,
};
};
const defineQuestionDataByLanguage = (question, lang) => {
const answerLang = languages[lang] || languages.default;
return {
labelLang: question[answerLang],
answerLang,
};
};