Last active
December 6, 2016 22:52
-
-
Save grosscol/4a5b2a7653a59ba86e3c3deb71abbb5b to your computer and use it in GitHub Desktop.
List of nodes with ancestors and corresponding tree structure with children.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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