Skip to content

Commit 54a4711

Browse files
author
임빛나
committed
해쉬 풀이 업데이트
1 parent 06b68bb commit 54a4711

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed
+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<html>
2+
<head>
3+
<meta charset="UTF-8" />
4+
<title>출력결과</title>
5+
</head>
6+
<body>
7+
<script>
8+
function solution(participant, completion) {
9+
let answer = '';
10+
11+
const map = new Map();
12+
13+
for (let el of participant) {
14+
if (map.has(el)) {
15+
map.set(el, map.get(el) + 1);
16+
} else {
17+
map.set(el, 1);
18+
}
19+
}
20+
21+
for (let el of completion) {
22+
map.set(el, map.get(el) - 1);
23+
}
24+
25+
for (let [key, value] of map) {
26+
if (value === 1) return key;
27+
}
28+
29+
answer = participant[0];
30+
31+
return answer;
32+
}
33+
34+
let a = ['leo', 'kiki', 'eden'];
35+
let b = ['eden', 'kiki'];
36+
console.log(solution(a, b));
37+
</script>
38+
</body>
39+
</html>

0 commit comments

Comments
 (0)