TREE = {
const map = new Map();
input.forEach((orbit) => {
const [parent, child] = orbit.split(')');
if (!map.has(parent)) {
map.set(parent, { children: [child] });
} else {
const children = map.get(parent).children;
children.push(child);
map.set(parent, Object.assign(map.get(parent), { children }));
}
if (!map.has(child)) {
map.set(child, { children: [], parent });
} else {
map.set(child, Object.assign(map.get(child), { parent }));
}
});
return map;
}