Created
July 25, 2016 18:48
-
-
Save brianyu0717/bf5b28d5dbd21be5b493e33c93ab2bd1 to your computer and use it in GitHub Desktop.
Programming challenge
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
| Given an array of strings representing a tree. Translate this to a tree. | |
| Example. | |
| ["1", "1.1", "1.1.1", "1.2", "1.3", "1.3.1", "2", "2.1"] | |
| Would result in the below tree: | |
| { | |
| key: 'root', | |
| children: [{ | |
| key: '1', | |
| children: [{ | |
| key: '1.1', | |
| children: [{ | |
| key: '1.1.1', | |
| children:[] | |
| }] | |
| }, { | |
| key: '1.2', | |
| children: [] | |
| }, { | |
| key: '1.3', | |
| children: [{ | |
| key: '1.3.1', | |
| children:[] | |
| }] | |
| }] | |
| }, { | |
| key: '2', | |
| children: [{ | |
| key: '2.1', | |
| children:[] | |
| }] | |
| }] | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment