Skip to content

Commit 7a2e148

Browse files
author
gyeong-hyeon-kim
committed
Add 1 solution.
1 parent 2215541 commit 7a2e148

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed
+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//https://github.com/codeisneverodd/programmers-coding-test
2+
//완벽한 정답이 아닙니다.
3+
function solution(str1, str2) {
4+
var answer = 0;
5+
let compare1 = verifiedSlices(str1), compare2 = verifiedSlices(str2)
6+
const union = new Set([...compare1, ...compare2])
7+
let multiIntersectionLen = 0, multiUnionLen = 0
8+
for (const slice of union) {
9+
const compare1Count = compare1.filter(x => x === slice).length,
10+
compare2Count = compare2.filter(x => x === slice).length
11+
multiIntersectionLen += Math.min(compare1Count, compare2Count)
12+
multiUnionLen += Math.max(compare1Count, compare2Count)
13+
}
14+
answer = multiUnionLen === 0 ? 65536 : Math.floor(multiIntersectionLen / multiUnionLen * 65536)
15+
return answer;
16+
}
17+
18+
function verifiedSlices(str) {
19+
const onlyAlphabet = /[a-zA-Z]{2}/
20+
let result = []
21+
for (let i = 0; i < str.length - 1; i++) {
22+
const slice = str.slice(i, i + 2)
23+
if (onlyAlphabet.test(slice)) result.push(slice.toLowerCase())
24+
}
25+
return result
26+
}

0 commit comments

Comments
 (0)