Advertisement
bebo231312312321

Untitled

Mar 30th, 2023
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function pianist (input){
  2. let pianistsList = {}
  3. let PianistLine=input.splice(0,input.shift()).map(line=>{
  4.     [piece,composer , key ] = line.split("|")
  5.     if(!pianistsList.hasOwnProperty(piece))
  6.         pianistsList[piece] = {composer, key}
  7. })
  8. let comandLine = input.splice(0, input.indexOf("Stop")).map(line=>{let [command, a, b,c] = line.split("|")
  9. switch(command){ case "Add" : add(a,b,c); break;
  10. case "Remove":remove(a); break;
  11. case "ChangeKey":change (a,b); break;}
  12. })
  13. function add(a,b,c){ !pianistsList.hasOwnProperty(a)? (pianistsList[a]={composer: b, key: c,},
  14.       console.log (`${a} by ${b} in ${c} added to the collection!`)):console.log(`${a} is already in the collection!`)}
  15.     function remove(a){ pianistsList.hasOwnProperty(a)?(delete pianistsList[a],    
  16.         console.log(`Successfully removed ${a}!`)):console.log(`Invalid operation! ${a} does not exist in the collection.`)}      
  17.     function change (a,b){pianistsList.hasOwnProperty(a)?(pianistsList[a].key = b,
  18.         console.log(`Changed the key of ${a} to ${b}!`)):(console.log(`Invalid operation! ${a} does not exist in the collection.`))}
  19.        
  20.     for (let key in pianistsList){console.log(`${key} -> Composer: ${pianistsList[key].composer}, Key: ${pianistsList[key].key}`)}
  21.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement