Silviya7

1.Cafeteria

Apr 12th, 2024
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(input){
  2.  
  3.     ArrBaristas={};
  4.     const countBarista=input.shift();
  5.  
  6.     for (let i = 0; i < countBarista; i++) {
  7.         const [name, shift,coffees]=input[i].split(' ');
  8.         ArrBaristas[name]={shift, allcofees:coffees.split(',')}
  9.     }
  10.  
  11.     let k=0;
  12.     while(k<countBarista){
  13.           input.shift();
  14.           k++;
  15.     }
  16.     let Commandline= input.shift();  
  17.    while(Commandline !='Closed'){
  18.  
  19.     const[command,name,firsta,secondA]= Commandline.split(' / ');
  20.      const barista=ArrBaristas[name];
  21.  
  22.      let shift, coffeType;
  23.   switch(command){
  24.  
  25.     case 'Prepare':
  26.         shift=firsta.trim();
  27.         coffeType= secondA.trim();
  28.        if(barista.shift == shift && barista.allcofees.includes(coffeType)){
  29.  
  30.         console.log(`${name.trim()} has prepared a ${coffeType.trim()} for you!`);
  31.        }
  32.        else{
  33.         console.log(`${name} is not available to prepare a ${coffeType}.`);
  34.        }
  35.        break;
  36.  
  37.        case 'Change Shift':
  38.         shift=firsta;          
  39.         console.log(`${name.trim()} has updated his shift to: ${shift.trim()}`);
  40.         barista.shift=shift;
  41.         break;
  42.  
  43.         case 'Learn':      
  44.         coffeType=firsta;  
  45.         if(barista.allcofees.includes(coffeType)){    
  46.         console.log(`${name.trim()} knows how to make ${coffeType.trim()}.`);
  47.         }
  48.         else{
  49.           barista.allcofees.push(coffeType);
  50.           console.log(`${name} has learned a new coffee type: ${coffeType}.`)
  51.         }
  52.         break;    
  53.      
  54.     }
  55.    
  56.     Commandline=input.shift();
  57.  
  58. }
  59.  
  60. for (const key in ArrBaristas) {
  61.      
  62.        console.log(`Barista: ${key}, Shift: ${ArrBaristas[key].shift}, Drinks: ${ArrBaristas[key].allcofees.join(', ')}`);
  63.    
  64. }
  65.  
  66. }
Add Comment
Please, Sign In to add comment