Skip to content

Instantly share code, notes, and snippets.

@grosscol
Last active December 6, 2016 22:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save grosscol/4a5b2a7653a59ba86e3c3deb71abbb5b to your computer and use it in GitHub Desktop.
Save grosscol/4a5b2a7653a59ba86e3c3deb71abbb5b to your computer and use it in GitHub Desktop.
List of nodes with ancestors and corresponding tree structure with children.
nodes = [
{id: '1', ancestor_ids: []},
{id: '12', ancestor_ids: ['1']},
{id: '13', ancestor_ids: ['1']},
{id: '124', ancestor_ids: ['1','12']},
{id: '125', ancestor_ids: ['1','12']},
{id: '136', ancestor_ids: ['1','13']},
{id: '1367', ancestor_ids: ['1','13','136']},
{id: '1368', ancestor_ids: ['1','13','136']},
{id: '19', ancestor_ids: ['1']}
]
tree = {
id: '1', children: [
{id: '19', children:[]},
{id: '12', children:[
{id: '124', children: []},
{id: '125', children: []}
]},
{id: '13', children:[
{id: '136', children: [
{id: '1367', children:[]},
{id: '1368', children:[]}
]}
]}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment