Implement buildTree(flatNodes, idKey, parentKey)
Comment threads, org charts, category trees, all delivered flat from an API and rendered nested. Write buildTree(flatNodes, idKey, parentKey) that turns a flat array into a nested tree: each node gets a children array, and nodes whose parentKey is missing/null/unresolvable become top-level roots.
buildTree(
[{ id: 1, parentId: null }, { id: 2, parentId: 1 }, { id: 3, parentId: 1 }],
"id", "parentId"
);
// [{ id: 1, parentId: null, children: [
// { id: 2, parentId: 1, children: [] },
// { id: 3, parentId: 1, children: [] }
// ]}]