Skip to content

Instantly share code, notes, and snippets.

@n0f3 n0f3/kewxmv.markdown
Created May 31, 2018

Embed
What would you like to do?
KewxmV
function org(arr) {
let managers = {};
function getChart(level, people) {
for (let reportee = 0; reportee < people.length; ++reportee) {
let newManager = people[reportee];
if (managers[newManager] !== undefined) {
print(level, people[reportee]);
getChart(level + 1, managers[people[reportee]]);
delete managers[people[reportee]];
} else {
print(level, people[reportee]);
}
}
}
function print(level, person) {
console.log('....'.repeat(level) + person);
}
for (let i = 0; i < arr.length; ++i) {
let people = arr[i];
let manager = people[0];
managers[manager] = people.split(',').slice(1);
}
let keys = Object.keys(managers);
let level = 0;
for (let key = 0; key < keys.length; ++key) {
if (managers[keys[key]] !== undefined) {
print(level, [keys[key]]);
let reportees = managers[keys[key]];
getChart(level + 1, reportees);
}
}
}
org([
'A,B,C,D',
'B,E,F',
'D,G,I',
'G,H',
]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.