function chatSystem(){
let user = new Map();
let onlineUsers = new Set();
function login(id){
if (!onlineUsers.has(id)){
onlineUsers.add(id);
user.set(id,(user.get(id) || 0) + 1 )
}
}
function logout(id){
if (onlineUsers.has(id)){
onlineUsers.delete(id);
}
}
function isOnline(id){
if (onlineUsers.has(id)){
return true
}else{
return false
}
}
function countOnline(){
return onlineUsers.size
}
function countLogins(id){
return (user.get(id) || 0 )
}
return {
login,
logout,
isOnline,
countOnline,
countLogins
}
}
const myChat = chatSystem();
myChat.login(1);
myChat.login(3);
myChat.login(2);
myChat.login(4);
console.log(myChat.countOnline());
myChat.logout(1);
console.log(myChat.countOnline());
myChat.login(1);
console.log(myChat.countLogins(1));
console.log(myChat.isOnline(4));
console.log(myChat.isOnline(1));
myChat.logout(2);
console.log(myChat.isOnline(2));
ZnVuY3Rpb24gY2hhdFN5c3RlbSgpewogICAKICAgIGxldCB1c2VyID0gbmV3IE1hcCgpOwogICAgbGV0IG9ubGluZVVzZXJzID0gbmV3IFNldCgpOwoKICAgIGZ1bmN0aW9uIGxvZ2luKGlkKXsKICAgICAgICBpZiAoIW9ubGluZVVzZXJzLmhhcyhpZCkpewogICAgICAgICAgIG9ubGluZVVzZXJzLmFkZChpZCk7CiAgICAgICAgICAgdXNlci5zZXQoaWQsKHVzZXIuZ2V0KGlkKSB8fCAwKSArIDEgKQogICAgICAgIH0KICAgIH0KICAgIGZ1bmN0aW9uIGxvZ291dChpZCl7CiAgICAgICAgaWYgKG9ubGluZVVzZXJzLmhhcyhpZCkpewogICAgICAgICAgICBvbmxpbmVVc2Vycy5kZWxldGUoaWQpOwogICAgICAgIH0KICAgIH0KICAgIGZ1bmN0aW9uIGlzT25saW5lKGlkKXsKICAgICAgICBpZiAob25saW5lVXNlcnMuaGFzKGlkKSl7CiAgICAgICAgICAgcmV0dXJuIHRydWUKICAgICAgICB9ZWxzZXsKICAgICAgICAgICAgcmV0dXJuIGZhbHNlCiAgICAgICAgfQogICAgfQogICAgZnVuY3Rpb24gY291bnRPbmxpbmUoKXsKICAgICAgICByZXR1cm4gb25saW5lVXNlcnMuc2l6ZQogICAgfSAgCiAgICBmdW5jdGlvbiBjb3VudExvZ2lucyhpZCl7CiAgICAgcmV0dXJuICh1c2VyLmdldChpZCkgfHwgMCApCiAgICB9IAogICAgcmV0dXJuIHsKICAgICAgICBsb2dpbiwKICAgICAgICBsb2dvdXQsCiAgICAgICAgaXNPbmxpbmUsCiAgICAgICAgY291bnRPbmxpbmUsCiAgICAgICAgY291bnRMb2dpbnMKICAgIH0KfQoKY29uc3QgbXlDaGF0ID0gY2hhdFN5c3RlbSgpOwpteUNoYXQubG9naW4oMSk7Cm15Q2hhdC5sb2dpbigzKTsKbXlDaGF0LmxvZ2luKDIpOwpteUNoYXQubG9naW4oNCk7CmNvbnNvbGUubG9nKG15Q2hhdC5jb3VudE9ubGluZSgpKTsgCm15Q2hhdC5sb2dvdXQoMSk7CmNvbnNvbGUubG9nKG15Q2hhdC5jb3VudE9ubGluZSgpKTsgCm15Q2hhdC5sb2dpbigxKTsKY29uc29sZS5sb2cobXlDaGF0LmNvdW50TG9naW5zKDEpKTsgIApjb25zb2xlLmxvZyhteUNoYXQuaXNPbmxpbmUoNCkpOwpjb25zb2xlLmxvZyhteUNoYXQuaXNPbmxpbmUoMSkpOyAKbXlDaGF0LmxvZ291dCgyKTsKY29uc29sZS5sb2cobXlDaGF0LmlzT25saW5lKDIpKTsgCg==