Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const queue = [];
- const append = (patientsName) => {
- queue.push(patientsName);
- console.log("OK");
- };
- const insert = (position, patientsName) => {
- if (position >= 0 && position <= queue.length) {
- queue.splice(position, 0, patientsName);
- console.log("OK");
- } else {
- console.log("Error");
- }
- };
- const find = (patientsName) => {
- const count = queue.filter((person) => person === patientsName).length;
- console.log(count);
- };
- const examine = (count) => {
- if (count <= queue.length) {
- const examinedPeople = queue.splice(0, count);
- console.log(examinedPeople.join(" "));
- } else {
- console.log("Error");
- }
- };
- for (let i = 0; ; i++) {
- const command = gets();
- if (command === "End") {
- break;
- }
- const [cmd, ...params] = command.split(" ");
- if (cmd === "Append") {
- append(params[0]);
- } else if (cmd === "Insert") {
- insert(Number(params[0]), params[1]);
- } else if (cmd === "Find") {
- find(params[0]);
- } else if (cmd === "Examine") {
- examine(Number(params[0]));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement