Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(input){
- let inbox = {};
- for(let i = 0; i < input.length; i++){
- let [command, username, email] = input[i].split('->');
- // console.log(input);
- switch(command){
- case "Add":
- if(!inbox.hasOwnProperty(username)){
- inbox[username] = [];
- // console.log(inbox);
- } else {
- console.log(`${username} is already registered`);
- }
- break;
- case "Send":
- if(inbox.hasOwnProperty(username)){
- inbox[username].push(email);
- }
- // console.log(inbox);
- break;
- case "Delete":
- if(inbox.hasOwnProperty(username)){
- delete inbox[username];
- } else {
- console.log(`${username} not found!`);
- }
- break;
- case "Statistics":
- break;
- }
- }
- let sortedByEmail = Object.entries(inbox).sort((a, b) => b[1] - a[1]);
- // console.log(sortedByEmail);
- let sortedByUsername = sortedByEmail.sort((a, b) => a[0].localeCompare(b[0]));
- // console.log(sortedByUsername);
- console.log(`Users count: ${sortedByUsername.length}`);
- for(let kvp of sortedByUsername){
- console.log(`${kvp[0]}`);
- for(let kkk of kvp[1]){
- console.log(` - ${kkk}`);
- }
- }
- }
Add Comment
Please, Sign In to add comment