Skip to content

Instantly share code, notes, and snippets.

@masterots
Last active December 14, 2015 14:39
Show Gist options
  • Save masterots/5102622 to your computer and use it in GitHub Desktop.
Save masterots/5102622 to your computer and use it in GitHub Desktop.
json organizer
var correct = [];
var currentDepth = -1;
var recurse = function( children )
{
var item;
currentDepth++;
while( (item = treeData.shift()) !== undefined )
{
if( item.depth == currentDepth )
{
children.push(item);
item.children = [];
recurse(item.children);
continue;
}
treeData.unshift(item);
break;
}
currentDepth--;
};
recurse(correct);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment