Skip to content

Instantly share code, notes, and snippets.

@bel1k0v
Last active February 16, 2016 21:07
Show Gist options
  • Save bel1k0v/9870806 to your computer and use it in GitHub Desktop.
Save bel1k0v/9870806 to your computer and use it in GitHub Desktop.
max-children-sort
function getMaxDepth(node) {
var max;
if (node.children) {
var c = node.children.length;
max = node.children[0].depth;
for (var i = 0; i < c; ++i) {
max = getMaxDepth(node.children[i]);
}
} else {
max = node.depth;
}
return max;
}
return getMaxDepth(a) > getMaxDepth(b) ? 1 : -1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment