ErolKZ

Untitled

Nov 15th, 2021
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1.  
  2. function solve(arr) {
  3.  
  4.  
  5. let companies = {};
  6.  
  7. let arr2 = [];
  8.  
  9.  
  10.  
  11. for (let el of arr) {
  12.  
  13. let cur = el.split(' -> ');
  14.  
  15.  
  16. if (companies.hasOwnProperty(cur[0])) {
  17.  
  18. companies[cur[0]].push(cur[1]);
  19.  
  20. } else {
  21.  
  22. companies[cur[0]] = [cur[1]];
  23.  
  24. }
  25.  
  26.  
  27. }
  28.  
  29.  
  30. for (let key in companies) {
  31.  
  32. arr2.push([key, companies[key]]);
  33.  
  34. }
  35.  
  36. // console.log(arr2);
  37.  
  38.  
  39. arr2.sort((a, b) => a[0].localeCompare(b[0]));
  40.  
  41.  
  42. for (let el of arr2) {
  43.  
  44. el[1] = [...new Set(el[1])];
  45.  
  46.  
  47. console.log(el[0]);
  48.  
  49. for (let el2 of el[1]) {
  50.  
  51. console.log(`-- ${el2}`);
  52.  
  53. }
  54.  
  55.  
  56.  
  57. }
  58.  
  59.  
  60.  
  61.  
  62. }
  63.  
Advertisement
Add Comment
Please, Sign In to add comment