daily pastebin goal
54%
SHARE
TWEET

01. Concert

a guest Jan 11th, 2019 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function manageConcert(arr) {
  2.     let addMembers = {};
  3.     let playTime = {};
  4.     let totalTime = 0;
  5.     let bandNameToPRint = arr.pop();
  6.  
  7.     for (let i = 0; i < arr.length; i++) {
  8.         let currentLine = arr[i];
  9.         if (currentLine === 'start of concert') {
  10.             console.log(`Total time: ${totalTime}`);
  11.  
  12.             let sortedByTime = Object.entries(playTime)
  13.                 .sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0]));
  14.  
  15.             for (let band of sortedByTime) {
  16.                 let [bandName, time] = band;
  17.  
  18.                 console.log(`${bandName} -> ${time}`);
  19.             }
  20.  
  21.             console.log(bandNameToPRint);
  22.  
  23.             let allMembers = addMembers[bandNameToPRint];
  24.  
  25.             for (let mem of allMembers) {
  26.                 console.log(`=> ${mem}`);
  27.             }
  28.  
  29.  
  30.         } else {
  31.             let [command, group, values] = currentLine.split('; ');
  32.  
  33.             if (command === 'Play') {
  34.                 let time = Number(values);
  35.  
  36.                 if (!playTime.hasOwnProperty(group)) {
  37.                     playTime[group] = 0;
  38.                 }
  39.                 playTime[group] += time;
  40.                 totalTime += time;
  41.             } else if (command === 'Add') {
  42.                 let members = values.split(', ');
  43.  
  44.                 if (!addMembers.hasOwnProperty(group)) {
  45.                     addMembers[group] = [];
  46.                 }
  47.  
  48.  
  49.                 for (let member of members) {
  50.  
  51.                     if (!addMembers[group].includes(member)) {
  52.                         addMembers[group].push(member);
  53.                     }
  54.  
  55.                 }
  56.             }
  57.  
  58.  
  59.  
  60.         }
  61.     }
  62. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top