Advertisement
bai_onzi

doctorsOffice.js

Jun 29th, 2023
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const queue = [];
  2.  
  3. const append = (patientsName) => {
  4.   queue.push(patientsName);
  5.   console.log("OK");
  6. };
  7.  
  8. const insert = (position, patientsName) => {
  9.   if (position >= 0 && position <= queue.length) {
  10.     queue.splice(position, 0, patientsName);
  11.     console.log("OK");
  12.   } else {
  13.     console.log("Error");
  14.   }
  15. };
  16.  
  17. const find = (patientsName) => {
  18.   const count = queue.filter((person) => person === patientsName).length;
  19.   console.log(count);
  20. };
  21.  
  22. const examine = (count) => {
  23.   if (count <= queue.length) {
  24.     const examinedPeople = queue.splice(0, count);
  25.     console.log(examinedPeople.join(" "));
  26.   } else {
  27.     console.log("Error");
  28.   }
  29. };
  30.  
  31. for (let i = 0; ; i++) {
  32.     const command = gets();
  33.  
  34.     if (command === "End") {
  35.       break;
  36.     }
  37.  
  38.     const [cmd, ...params] = command.split(" ");
  39.  
  40.     if (cmd === "Append") {
  41.       append(params[0]);
  42.     } else if (cmd === "Insert") {
  43.       insert(Number(params[0]), params[1]);
  44.     } else if (cmd === "Find") {
  45.       find(params[0]);
  46.     } else if (cmd === "Examine") {
  47.       examine(Number(params[0]));
  48.     }
  49.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement