Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(args) {
- const companies = {};
- args.forEach((element) => {
- const [company, emplId] = element.split(' -> ');
- if (!Object.prototype.hasOwnProperty.call(companies, company)) {
- companies[company] = [];
- }
- if (Object.prototype.hasOwnProperty.call(companies, company)) {
- const isFind = companies[company].find((empl) => empl === emplId);
- if (isFind === undefined) {
- companies[company].push(emplId);
- }
- }
- });
- const sortByName = Object.entries(companies).sort((a, b) => a[0].localeCompare(b[0]));
- sortByName.forEach((element) => {
- const [companyName, employeeId] = element;
- console.log(`${companyName} \n-- ${employeeId.join('\n-- ')}`);
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement