Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function companyUsers(input) {
- const companiesInfo = [...input];
- const companies = {};
- companiesInfo.forEach((currentCompany) => {
- const company = currentCompany.split(' -> ');
- const companyName = company[0];
- const id = company[1];
- if (!companies.hasOwnProperty(companyName)) {
- companies[companyName] = [id];
- } else {
- const currentID = id;
- companies[companyName].push(currentID);
- }
- companies[companyName] = [...new Set(companies[companyName])];
- });
- const sortedCompanies = Object.entries(companies).sort((a, b) =>
- a[0].localeCompare(b[0])
- );
- for (const company of sortedCompanies) {
- const name = company[0];
- const ids = company[1];
- console.log(name);
- ids.forEach(id => {
- console.log(`-- ${id}`);
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement