Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save tranthaison1231/a875304843ba92056ae25615d3bad252 to your computer and use it in GitHub Desktop.

Select an option

Save tranthaison1231/a875304843ba92056ae25615d3bad252 to your computer and use it in GitHub Desktop.
employment-hero-test
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