Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function concert(input) {
- let bands = {};
- let totalTime = 0;
- while ((line = input.shift()) !== 'start of concert') {
- let [command, name, membersOrTime] = line.split('; ');
- if (command === 'Add') {
- addband(name);
- membersOrTime.split(', ').forEach(member => {
- if (!bands[name].members.includes(member)) {
- bands[name].members.push(member);
- }
- });
- } else {
- let time = Number(membersOrTime);
- addband(name);
- bands[name].time += time;
- totalTime += time;
- }
- }
- console.log(`Total time: ${totalTime}`);
- Object.entries(bands)
- .sort((a, b) => b[1].time - a[1].time || a[0].localeCompare(b[0]))
- .forEach(band => console.log(`${band[0]} -> ${band[1].time}`));
- let bandName = input.shift();
- console.log(bandName);
- Object.values(bands[bandName])[1].forEach(member => console.log(`=> ${member}`));
- function addband(name) {
- if (!bands[name]) {
- bands[name] = {
- time: 0,
- members: []
- }
- }
- }
- }
- concert(['Play; The Beatles; 2584',
- 'Add; The Beatles; John Lennon, Paul McCartney, George Harrison, Ringo Starr',
- 'Add; Eagles; Glenn Frey, Don Henley, Bernie Leadon, Randy Meisner',
- 'Play; Eagles; 1869',
- 'Add; The Rolling Stones; Brian Jones, Mick Jagger, Keith Richards',
- 'Add; The Rolling Stones; Brian Jones, Mick Jagger, Keith Richards, Bill Wyman, Charlie Watts, Ian Stewart',
- 'Play; The Rolling Stones; 4239',
- 'start of concert',
- 'The Rolling Stones']);
- concert(['Add; The Beatles; John Lennon, Paul McCartney',
- 'Add; The Beatles; Paul McCartney, George Harrison',
- 'Add; The Beatles; George Harrison, Ringo Starr',
- 'Play; The Beatles; 3698',
- 'Play; The Beatles; 3828',
- 'start of concert',
- 'The Beatles']);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement