SHARE
TWEET

Untitled

a guest Mar 23rd, 2019 51 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(input){
  2.     let finalBand = input.pop()
  3.     input.pop()
  4.     let bandsParams = {
  5.         bands: {},
  6.         totalTime: 0
  7.     }
  8.         for(let inp of input){
  9.             if(inp.includes('Play')){
  10.                 let [command,band,time] = inp.split("; ")
  11.                 time = +time;
  12.                 if(bandsParams.bands.hasOwnProperty(band)){
  13.                     bandsParams.bands[band].time += time
  14.                    
  15.                 }else{
  16.                     bandsParams.bands[band] = {
  17.                         time: time,
  18.                         totalmembers: []
  19.                     }
  20.                 }
  21.                 bandsParams.totalTime += time;
  22.             }else if(inp.includes('Add')){
  23.                 let [command,band,...members] =inp.split("; ")
  24.                 members = members[0].split(", ")
  25.                 if(bandsParams.bands.hasOwnProperty(band)){
  26.                     bandsParams.bands[band].totalmembers.push([...new Set(members)])
  27.  
  28.                 }else{
  29.                     bandsParams.bands[band] ={
  30.                         time: 0,
  31.                         totalmembers: [...new Set(members)]
  32.                     }
  33.                 }
  34.                
  35.             }
  36.         }
  37.     console.log(`Total time: ${bandsParams.totalTime}`)
  38.     for(let [key,value] of Object.entries(bandsParams.bands)){
  39.         console.log(val)
  40.      
  41.     }
  42.     }
  43.     solve([ 'Play; The Beatles; 2584',
  44.     'Add; The Beatles; John Lennon, Paul McCartney, George Harrison, Ringo Starr',
  45.     'Add; Eagles; Glenn Frey, Don Henley, Bernie Leadon, Randy Meisner',
  46.     'Play; Eagles; 1869',
  47.     'Add; The Rolling Stones; Brian Jones, Mick Jagger, Keith Richards',
  48.     'Add; The Rolling Stones; Brian Jones, Mick Jagger, Keith Richards, Bill Wyman, Charlie Watts, Ian Stewart',
  49.     'Play; The Rolling Stones; 4239',
  50.     'start of concert',
  51.     'The Rolling Stones' ])
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