Advertisement
Guest User

Untitled

a guest
Jul 8th, 2019
427
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. function solve(input) {
  2.  
  3. let companies = {};
  4.  
  5. for (const elem of input) {
  6.  
  7. let [company, id] = elem.split(' -> ');
  8.  
  9. if(!companies.hasOwnProperty(company)) {
  10.  
  11. companies[company]=id;
  12.  
  13. } else {
  14. let currentValue = companies[company];
  15. let newValue = currentValue + ',' +id;
  16. companies[company] = newValue;
  17.  
  18. }
  19.  
  20. }
  21.  
  22. let sorted =[...Object.entries(companies)];
  23. sorted.sort((a,b) =>
  24. a[0].localeCompare(b[0]));
  25.  
  26. for(let elem of sorted){
  27. console.log(elem[0]);
  28. let numberIds = elem[1].split(',');
  29. let set = new Set(numberIds);
  30.  
  31. for(let number of set) {
  32. console.log(`-- ${number}`);
  33.  
  34. }
  35. }
  36.  
  37. }
  38.  
  39. solve([ 'SoftUni -> AA12345',
  40. 'SoftUni -> CC12344',
  41. 'Lenovo -> XX23456',
  42. 'SoftUni -> AA12345',
  43. 'Movement -> DD11111' ]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement