✨ 문제 ✨

✨ 정답 ✨
function solution(record) {
var answer = [];
let infos=new Object();
for (let i=0;i<record.length;i++){
let [action, userId, name]=record[i].split(' ')
if (action==='Enter'){
infos[userId]=name;
}else if (action==='Change'){
infos[userId]=name;
}
}
for (let i=0;i<record.length;i++){
let [action, userId, name]=record[i].split(' ');
if (action==='Enter'){
answer.push(infos[userId]+'님이 들어왔습니다.')
}else if (action==='Leave'){
answer.push(infos[userId]+'님이 나갔습니다.')
}
}
return answer;
}
function solution(record) {
var answer = [];
let infos=new Object();
let changed =[]
for (let i=0;i<record.length;i++){
let cut=record[i].split(' ')
if (!Object.keys(infos).includes(cut[1])){
infos[cut[1]]=cut[2];
}
if (cut[0]==='Change'){
if (Object.keys(infos).includes(cut[1])){
infos[cut[1]]=cut[2]
}
}
if (cut[0]==='Enter'){
if (Object.keys(infos).includes(cut[1])){
infos[cut[1]]=cut[2]
}
}
}
for (let i=0;i<record.length;i++){
let cut=record[i].split(' ');
if (cut[0]==='Enter'){
answer.push(infos[cut[1]]+'님이 들어왔습니다.')
}else if (cut[0]==='Leave'){
answer.push(infos[cut[1]]+'님이 나갔습니다.')
}
}
return answer;
}
🧵 참고한 정답지 🧵
💡💡 기억해야 할 점 💡💡