Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(input){
- ArrBaristas={};
- const countBarista=input.shift();
- for (let i = 0; i < countBarista; i++) {
- const [name, shift,coffees]=input[i].split(' ');
- ArrBaristas[name]={shift, allcofees:coffees.split(',')}
- }
- let k=0;
- while(k<countBarista){
- input.shift();
- k++;
- }
- let Commandline= input.shift();
- while(Commandline !='Closed'){
- const[command,name,firsta,secondA]= Commandline.split(' / ');
- const barista=ArrBaristas[name];
- let shift, coffeType;
- switch(command){
- case 'Prepare':
- shift=firsta.trim();
- coffeType= secondA.trim();
- if(barista.shift == shift && barista.allcofees.includes(coffeType)){
- console.log(`${name.trim()} has prepared a ${coffeType.trim()} for you!`);
- }
- else{
- console.log(`${name} is not available to prepare a ${coffeType}.`);
- }
- break;
- case 'Change Shift':
- shift=firsta;
- console.log(`${name.trim()} has updated his shift to: ${shift.trim()}`);
- barista.shift=shift;
- break;
- case 'Learn':
- coffeType=firsta;
- if(barista.allcofees.includes(coffeType)){
- console.log(`${name.trim()} knows how to make ${coffeType.trim()}.`);
- }
- else{
- barista.allcofees.push(coffeType);
- console.log(`${name} has learned a new coffee type: ${coffeType}.`)
- }
- break;
- }
- Commandline=input.shift();
- }
- for (const key in ArrBaristas) {
- console.log(`Barista: ${key}, Shift: ${ArrBaristas[key].shift}, Drinks: ${ArrBaristas[key].allcofees.join(', ')}`);
- }
- }
Add Comment
Please, Sign In to add comment