function solution(record) {
const users = {}
const orders = []
for(let rec of record){
const [action, username, nickname = '' ] = rec.split(' ')
if(action === 'Enter'){
users[username] = nickname;
orders.push([action, username]);
} else if(action === 'Leave'){
orders.push([action, username]);
} else {
users[username] = nickname;
}
}
const result = []
for(let rec of orders){
const [action, username] = rec
if(action === "Enter"){
result.push(`${users[username]}님이 들어왔습니다.` )
} else {
result.push(`${users[username]}님이 나갔습니다.` )
}
}
return result
}
const [action, username, nickname = '' ] = rec.split(' ')
users[username] = nickname;
function solution(record) {
const users = {}
const orders = []
const text = {
Enter: '님이 들어왔습니다.',
Leave: '님이 나갔습니다.',
}
for(let rec of record){
const [action, username, nickname = '' ] = rec.split(' ')
if(action !== 'Change') orders.push([action, username]);
if(nickname) users[username] = nickname;
}
return orders.map(v => users[v[1]] + text[v[0]])
}