Skip to content

Commit 4b3f8ee

Browse files
committed
오픈채팅방 / 심화
1 parent 16b93e3 commit 4b3f8ee

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
function solution(record) {
2+
const nicknames = {};
3+
const result = [];
4+
5+
record.forEach((entry) => {
6+
const [action, userId, nickname] = entry.split(" ");
7+
if (action !== "Leave") {
8+
nicknames[userId] = nickname;
9+
}
10+
});
11+
12+
record.forEach((entry) => {
13+
const [action, userId] = entry.split(" ");
14+
if (action === "Enter") {
15+
result.push(`${nicknames[userId]}님이 들어왔습니다.`);
16+
} else if (action === "Leave") {
17+
result.push(`${nicknames[userId]}님이 나갔습니다.`);
18+
}
19+
});
20+
21+
return result;
22+
}

0 commit comments

Comments
 (0)