1var s1 = "abcd";
2var s2 = "aad";
3var count=0;
4function match(s1,s2)
5{
6for(let i in s1)
7s2.includes(s1[i])?count++:false;
8console.log(count)
9}
10match(s1,s2)
1//Solution:
2function getSameCount(str1, str2) {
3 let count = 0;
4 const obj = str2.split("");
5 for(str of str1){
6 let idx = obj.findIndex(s => s === str);
7 if(idx >= 0){
8 count++;
9 obj.splice(idx, 1);
10 }
11 }
12 return count;
13}
14
15//Test:
16console.log(getSameCount("abcd", "aad"));
17console.log(getSameCount("geeksforgeeks", "platformforgeeks"));
18console.log(getSameCount("aad", "abcd"));
19console.log(getSameCount("platformforgeeks", "geeksforgeeks"));