let initToIndex = arr1.reduce((acc, item, idx) => {
acc[item[0].init] = idx;
return acc;
}, {});
arr2.flat().forEach(x => {
let idx = initToIndex[x.init];
if (!initToIndex.hasOwnProperty(x.init)) {
idx = arr1.push([]) - 1;
initToIndex[x.init] = idx;
};
arr1[idx].push(x);
});
window.addEventListener("hashchange", (e) => {
document.querySelectorAll('.lang > a').forEach(el = el.classList.remove('active'));
switch(location.hash) {
case '#en': document.getElementById('lang-en').classList.add('active'); break;
case '#fr': document.getElementById('lang-fr').classList.add('active'); break;
default: break;
};
}, false);
// Сортируем
rootEl.insertBefore(dragEl, target.previousElementSibling ? target.nextElementSibling : target );