Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(input){
- let finalBand = input.pop()
- input.pop()
- let bandsParams = {
- bands: {},
- totalTime: 0
- }
- for(let inp of input){
- if(inp.includes('Play')){
- let [command,band,time] = inp.split("; ")
- time = +time;
- if(bandsParams.bands.hasOwnProperty(band)){
- bandsParams.bands[band].time += time
- }else{
- bandsParams.bands[band] = {
- time: time,
- totalmembers: []
- }
- }
- bandsParams.totalTime += time;
- }else if(inp.includes('Add')){
- let [command,band,...members] =inp.split("; ")
- members = members[0].split(", ")
- if(bandsParams.bands.hasOwnProperty(band)){
- bandsParams.bands[band].totalmembers.push([...new Set(members)])
- }else{
- bandsParams.bands[band] ={
- time: 0,
- totalmembers: [...new Set(members)]
- }
- }
- }
- }
- console.log(`Total time: ${bandsParams.totalTime}`)
- for(let [key,value] of Object.entries(bandsParams.bands)){
- console.log(val)
- }
- }
- solve([ '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' ])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement