Advertisement
Lulunga

07. Company Users Associative Arrays

Jul 11th, 2019
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. function solve(input) {
  2. let companies = {};
  3. for (const elem of input) {
  4. let [company, id] = elem.split(' -> ');
  5. if (!companies.hasOwnProperty(company)) {
  6. companies[company] = [];
  7. }
  8. companies[company].push(id);
  9. }
  10. let sorted = Object.entries(companies);
  11. sorted.sort((a, b) => a[0].localeCompare(b[0]));
  12. for (let elem of sorted) {
  13. console.log(elem[0]);
  14. let set = new Set(elem[1]);
  15. for (let number of set) {
  16. console.log(`-- ${number}`);
  17. }
  18. }
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement