function createTree(arr, structure) {
const tree = Object.fromEntries(arr.map(n => [ n.id, { ...n, elements: [] } ]));
structure
.filter(n => n.parentId !== null)
.forEach(n => tree[n.parentId].elements.push(tree[n.id]));
return structure
.filter(n => n.parentId === null)
.map(n => tree[n.id]);
}