Advertisement
bebo231312312321

Untitled

Mar 30th, 2023
51
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){ if(!pianistsList.hasOwnProperty(a)){
  14.       pianistsList[a]={composer: b, key: c,}
  15.       console.log (`${a} by ${b} in ${c} added to the collection!`)
  16. }else{console.log(`${a} is already in the collection!`)}
  17.     }
  18.  
  19. function remove(a){ if(pianistsList.hasOwnProperty(a)){
  20.     delete pianistsList[a]
  21. console.log(`Successfully removed ${a}!`)
  22. }else{console.log(`Invalid operation! ${a} does not exist in the collection.`)}
  23. }
  24.  
  25. function change (a,b){if(pianistsList.hasOwnProperty(a)){ pianistsList[a].key = b
  26. console.log(`Changed the key of ${a} to ${b}!`)
  27. }else(console.log(`Invalid operation! ${a} does not exist in the collection.`))
  28. }
  29.  
  30. for (let key in pianistsList){console.log(`${key} -> Composer: ${pianistsList[key].composer}, Key: ${pianistsList[key].key}`)}
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement