find common characters in two strings javascript 1

find common characters in two strings javascript

var s1 = "abcd";
var s2 = "aad";
var count=0;
function match(s1,s2)
{
for(let i in s1)
s2.includes(s1[i])?count++:false;
console.log(count)
}
match(s1,s2)

Here is what the above code is Doing:
1. We are taking two strings as input.
2. We are iterating over the first string and checking if the second string contains the character of the first string.
3. If the second string contains the character of the first string, we are incrementing the count variable.
4. Finally, we are printing the count variable.

Similar Posts