Created
September 14, 2017 11:02
-
-
Save Grytsak/68f2d200073658d09db816694008b394 to your computer and use it in GitHub Desktop.
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
| 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