Created
October 18, 2023 09:11
-
-
Save tranthaison1231/a875304843ba92056ae25615d3bad252 to your computer and use it in GitHub Desktop.
employment-hero-test
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
| function produceChart(csv) { | |
| const strs = csv.split('\n'); | |
| const data = {} | |
| strs.forEach(str => { | |
| if (str) { | |
| const [id, name, reportTo] = str.split(',') | |
| data[id] = { | |
| name, | |
| reportTo, | |
| } | |
| } | |
| }) | |
| let output = ''; | |
| function drawItem(item) { | |
| let level = 0; | |
| if (item.reportTo) { | |
| level = item.reportTo; | |
| } | |
| for (let i = 0; i < level; i++) { | |
| output += ' '; | |
| } | |
| output += item.name + '\n'; | |
| } | |
| Object.values(data).forEach(item => { | |
| drawItem(item) | |
| }) | |
| console.log(output); | |
| } | |
| produceChart(` | |
| 1,Ben,0 | |
| 2,Kate,1 | |
| 3,Damien,2 | |
| 4,Jane,1 | |
| 5,Meng,4 | |
| `); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment