Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function pianist (input){
- let pianistsList = {}
- let PianistLine=input.splice(0,input.shift()).map(line=>{
- [piece,composer , key ] = line.split("|")
- if(!pianistsList.hasOwnProperty(piece))
- pianistsList[piece] = {composer, key}
- })
- let comandLine = input.splice(0, input.indexOf("Stop")).map(line=>{let [command, a, b,c] = line.split("|")
- switch(command){ case "Add" : add(a,b,c); break;
- case "Remove":remove(a); break;
- case "ChangeKey":change (a,b); break;}
- })
- function add(a,b,c){ if(!pianistsList.hasOwnProperty(a)){
- pianistsList[a]={composer: b, key: c,}
- console.log (`${a} by ${b} in ${c} added to the collection!`)
- }else{console.log(`${a} is already in the collection!`)}
- }
- function remove(a){ if(pianistsList.hasOwnProperty(a)){
- delete pianistsList[a]
- console.log(`Successfully removed ${a}!`)
- }else{console.log(`Invalid operation! ${a} does not exist in the collection.`)}
- }
- function change (a,b){if(pianistsList.hasOwnProperty(a)){ pianistsList[a].key = b
- console.log(`Changed the key of ${a} to ${b}!`)
- }else(console.log(`Invalid operation! ${a} does not exist in the collection.`))
- }
- for (let key in pianistsList){console.log(`${key} -> Composer: ${pianistsList[key].composer}, Key: ${pianistsList[key].key}`)}
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement