function commonCharactersCount(str1: string, str2: string): number {
// Convert strings to sets of characters
const set1: Set<string> = new Set(str1);
const set2: Set<string> = new Set(str2);
// Find the intersection of the two sets
let count: number = 0;
for (const ch of set1) {
if (set2.has(ch)) {
count++;
}
}
return count;
}
const str1: string = "abcdefg";
const str2: string = "xayzgoe";
console.log(commonCharactersCount(str1, str2));
/*
run:
3
*/