Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save Grytsak/68f2d200073658d09db816694008b394 to your computer and use it in GitHub Desktop.

Select an option

Save Grytsak/68f2d200073658d09db816694008b394 to your computer and use it in GitHub Desktop.
var input = {
"name": "positive",
"children": [{
"name": "product service",
"children": [{
"name": "price",
"children": [{
"name": "cost",
"size": 8
}]
}, {
"name": "quality",
"children": [{
"name": "messaging",
"size": 4
}]
}]
}, {
"name": "customer service",
"children": [{
"name": "Personnel",
"children": [{
"name": "CEO",
"size": 7
}]
}]
}, {
"name": "product",
"children": [{
"name": "Apple",
"children": [{
"name": "iPhone 4",
"size": 10
}]
}]
}]
}
getDepth = function (obj) {
var depth = 0;
if (obj.children) {
obj.children.forEach(function (d) {
var tmpDepth = getDepth(d)
if (tmpDepth > depth) {
depth = tmpDepth
}
})
}
return 1 + depth
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment