Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function concert(input) {
- let time = {};
- let list = {};
- let totalTime = 0;
- for (let line of input) {
- if (line === "start of concert") {
- break;
- }
- let [command, band, timeOrMembers] = line.split("; ");
- if (command === "Add") {
- timeOrMembers = timeOrMembers.split(", ");
- if (!list.hasOwnProperty(band)) {
- list[band] = new Set();
- }
- timeOrMembers.forEach((member) => list[band].add(member))
- } else if (command === "Play") {
- timeOrMembers = Number(timeOrMembers);
- totalTime += timeOrMembers;
- if (!time.hasOwnProperty(band)) {
- time[band] = 0;
- }
- time[band] += timeOrMembers;
- }
- }
- console.log(`Total time: ${totalTime}`);
- let entries = Object.entries(time);
- entries.sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0])).forEach((tuple) => console.log(`${tuple[0]} -> ${tuple[1]}`))
- let bandToPrint = input.pop();
- console.log(bandToPrint)
- list[bandToPrint].forEach(member => console.log(`=> ${member}`))
- }
Advertisement
Add Comment
Please, Sign In to add comment