Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(input){
- let company = new Map();
- for (const line of input) {
- let [companyName, person] = line.split(' -> ');
- let namesList = [];
- if(!company.has(companyName)){
- namesList.push(person);
- company.set(companyName, namesList);
- }else{
- let currentList = company.get(companyName);
- currentList.push(person);
- company.set(companyName, Array.from(new Set(currentList)));
- }
- }
- Array.from(company).sort((a,b)=>{
- return a[0].localeCompare(b[0]);
- }).forEach(pair=>{
- console.log(`${pair[0]}`);
- pair[1].forEach(user=>{
- console.log(`-- ${user}`);
- })
- })
- }
Advertisement
Add Comment
Please, Sign In to add comment