dilyana2001

Untitled

Jul 19th, 2021 (edited)
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(arr) {
  2.     let result = {};
  3.     arr.forEach(line => {
  4.         let [company, id] = line.split(' -> ');
  5.         if (!result.hasOwnProperty(company)) result[company] = [];
  6.         if (!result[company].includes(id)) result[company].push(id);
  7.     })
  8.     Object.entries(result)
  9.         .sort((a, b) => a[0].localeCompare(b[0]))
  10.         .map(x => console.log(`${x[0]}\n-- ${x[1].join('\n-- ')}`));
  11. }
Add Comment
Please, Sign In to add comment