Advertisement
PPetkov2000

Programming Fundamentals - Roli The Coder

Dec 22nd, 2019
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(params) {
  2.   params.pop();
  3.   let events = {};
  4.  
  5.   for (let param of params) {
  6.     let [id, eventName, ...participants] = param.split(" ");
  7.  
  8.     if (!eventName.includes("#")) {
  9.       continue;
  10.     }
  11.  
  12.     if (!events.hasOwnProperty(id)) {
  13.       events[id] = {
  14.         eventId: id,
  15.         eventName: eventName,
  16.         participants: []
  17.       };
  18.     }
  19.  
  20.     if (events[id].eventId === id && events[id].eventName === eventName) {
  21.       participants.forEach(participant => {
  22.         if (!events[id].participants.includes(participant)) {
  23.           events[id].participants.push(participant);
  24.         }
  25.       });
  26.     }
  27.   }
  28.  
  29.   Object.entries(events)
  30.     .sort((a, b) => b[1].participants.length - a[1].participants.length)
  31.     .forEach(event => {
  32.       console.log(
  33.         `${event[1].eventName.slice(1)} - ${event[1].participants.length}`
  34.       );
  35.       event[1].participants
  36.         .sort((a, b) => a.localeCompare(b))
  37.         .forEach(participant => console.log(participant));
  38.     });
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement