Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function plantDiscovery(input){
- let countPlants=Number(input.shift());
- let obj={};
- let plants=input.splice(0,countPlants);
- for (let plant of plants){
- let [name,rarity]=plant.split("<->");
- rarity=Number(rarity);
- if(!obj.hasOwnProperty(name)){
- obj[name]= {
- rarity,
- rating:[]
- }
- }
- }
- let commands=input.splice(0,input.indexOf("Exhibition"));
- for(let line of commands){
- let [command,lineOth]=line.split(": ");
- let [plantName,value]=lineOth.split(" - ");
- value=Number(value);
- let avg=0;
- switch(command){
- case "Rate":
- if(!obj.hasOwnProperty(plantName)){
- console.log(`error`);
- }else {
- obj[plantName].rating.push(value);
- }
- break;
- case "Update":
- if(!obj.hasOwnProperty(plantName)){
- console.log(`error`);
- }else {
- obj[plantName].rarity=value;
- }
- break;
- case "Reset":
- if(!obj.hasOwnProperty(plantName)){
- console.log(`error`);
- }else {
- delete obj[plantName].rating;
- }
- break;
- }
- }
- //console.log(obj)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement