Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(args) {
- const users = {};
- let inputLine = args.shift();
- while (inputLine !== 'Statistics') {
- const [command, userName, email] = inputLine.split('->');
- switch (command) {
- case 'Add':
- if (!Object.prototype.hasOwnProperty.call(users, userName)) {
- const emails = [];
- users[userName] = { emails };
- } else {
- console.log(`${userName} is already registered`);
- }
- break;
- case 'Send':
- users[userName].emails.push(email);
- break;
- case 'Delete':
- if (Object.prototype.hasOwnProperty.call(users, userName)) {
- delete users[userName];
- } else {
- console.log(`${userName} not found!`);
- }
- break;
- default:
- break;
- }
- inputLine = args.shift();
- }
- console.log(`Users count: ${Object.keys(users).length}`);
- Object.entries(users)
- .sort((a, b) => b[1].emails.length - a[1].emails.length || a[0].localeCompare(b[0]))
- .forEach((el) => {
- const [name, arg1] = el;
- console.log(`${name}`);
- arg1.emails.forEach((email) => {
- console.log(` - ${email}`);
- });
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment