뉴스 클러스트링 https://programmers.co.kr/learn/courses/30/lessons/17677
const pattern_str = /[a-zA-Z]/;
// pattern_str.test(문자)
pattern_str.test("*"); // false
pattern_str.test("a"); // true
for (let i = 0; i < arr2.length; i++) {
if (arr1.indexOf(arr2[i]) >= 0) {
intersection.push(arr1.splice(arr1.indexOf(arr2[i]), 1));
}
union.push(arr2[i]);
}
for (let i = 0; i < arr1.length; i++) {
union.push(arr1[i]);
}
function solution(str1, str2) {
const pattern_str = /[a-zA-Z]/;
const arr1 = [];
const arr2 = [];
str1 = str1.split("");
str1 = str1.map((v) => v.toLowerCase());
str2 = str2.split("");
str2 = str2.map((v) => v.toLowerCase());
str1.forEach((_, index) => {
const first = str1[index];
const second = str1[index + 1];
if (
pattern_str.test(first) &&
pattern_str.test(second) &&
second !== undefined
)
arr1.push(first + second);
});
str2.forEach((_, index) => {
const first = str2[index];
const second = str2[index + 1];
if (
pattern_str.test(first) &&
pattern_str.test(second) &&
second !== undefined
)
arr2.push(first + second);
});
var intersection = []; // 중복포함, 교집합 배열 (multi set)
var union = []; // 중복포함, 합집합 배열
for (let i = 0; i < arr2.length; i++) {
if (arr1.indexOf(arr2[i]) >= 0) {
intersection.push(arr1.splice(arr1.indexOf(arr2[i]), 1));
}
union.push(arr2[i]);
}
for (let i = 0; i < arr1.length; i++) {
union.push(arr1[i]);
}
if (union.length === 0) return 65536;
if (intersection.length === 0) return 0;
return Math.floor((intersection.length / union.length) * 65536);
}