TZinovieva

Company Users JS Fundamentals

Mar 5th, 2023
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function companyEmployees(input) {
  2.     let companies = {};
  3.  
  4.     for (let line of input) {
  5.       let [company, employee] = line.split(" -> ");
  6.       if (!companies.hasOwnProperty(company)) {
  7.         companies[company] = new Set();
  8.       }
  9.       companies[company].add(employee);
  10.     }
  11.  
  12.     let sortedCompanies = Object.keys(companies).sort();
  13.  
  14.     for (let company of sortedCompanies) {
  15.       console.log(company);
  16.       for (let employee of companies[company]) {
  17.         console.log(`-- ${employee}`);
  18.       }
  19.     }
  20.   }
Advertisement
Add Comment
Please, Sign In to add comment