Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function nikulden(param){
- let records = {};
- let unlikedMeals = 0;
- for(let el of param){
- if(el === 'Stop'){
- break;
- }
- let [command,name,meal] = el.split('-');
- switch(command){
- case 'Like':
- if(!records[name]){
- records[name] = [];
- }
- if(!records[name].includes(meal)){
- records[name].push(meal);
- }
- ;break;
- case 'Unlike':
- if(records[name]){
- if(records[name].includes(meal)){
- let indMeal = records[name].indexOf(meal);
- records[name].splice(indMeal,1);
- console.log(`${name} doesn't like the ${meal}.`);
- unlikedMeals++;
- }else{
- console.log(`${name} doesn't have the ${meal} in his/her collection.`)
- }
- }else{
- console.log(`${name} is not at the party.`)
- }
- ;break;
- }
- }
- let arr = Object.entries(records);
- let comparator = (a,b) => b[1].length - a[1].length ||
- a[0].localeCompare(b[0]);
- arr = arr.sort(comparator);
- arr.forEach(el=>{
- console.log(`${el[0]}: ${el[1].join(', ')}`)
- })
- console.log(`Unliked meals: ${unlikedMeals}`)
- }
- // nikulden([
- // 'Like-Krisi-shrimps',
- // 'Like-Krisi-soup',
- // 'Like-Misho-salad',
- // 'Like-Pena-dessert',
- // 'Stop'
- // ]);
- nikulden([
- "Like-Krisi-shrimps",
- "Unlike-Vili-carp",
- "Unlike-Krisi-salad",
- "Unlike-Krisi-shrimps",
- "Stop"
- ])
Advertisement
Add Comment
Please, Sign In to add comment