Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function degustationParty(input) {
- let index = 0;
- let line = input[index];
- index++;
- let record = {};
- let dislikedCounter = 0;
- while (line !== "Stop") {
- let [command, username, meal] = line.split('-');
- let collection = [];
- if (command === 'Like') {
- if (!record.hasOwnProperty(username)) {
- record[username] = collection;
- record[username].push(meal);
- } else if (!collection.includes(meal)) {
- record[username].push(meal);
- }
- } else if (command === 'Dislike') {
- if (!record.hasOwnProperty(username)) {
- console.log(username, 'is not at the party.');
- } else if (!record[username].includes(meal)) {
- console.log(`${username} doesn't have the ${meal} in his/her collection.`);
- } else {
- dislikedCounter++;
- let mealIndex = record[username].indexOf(meal);
- record[username].splice(mealIndex, 1);
- console.log(`${username} doesn't like the ${meal}`);
- }
- }
- line = input[index];
- index++;
- }
- for (username in record) {
- console.log(`${username}: ${record[username].join(', ')}`);
- }
- console.log(`Unliked meals: ${dislikedCounter}`);
- }
- degustationParty(["Like-Krisi-shrimps",
- "Like-Krisi-soup",
- "Like-Penelope-dessert",
- "Like-Misho-salad",
- "Stop"]);
- console.log('---');
- degustationParty(["Like-Krisi-shrimps",
- "Dislike-Vili-carp",
- "Dislike-Krisi-salad",
- "Stop"]);
- console.log('---');
- degustationParty(["Like-Katy-fish",
- "Dislike-Katy-fish",
- "Stop"]);
Advertisement
Add Comment
Please, Sign In to add comment