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)
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)
find common characters in two strings javascript
//Solution:
function getSameCount(str1, str2) {
let count = 0;
const obj = str2.split("");
for(str of str1){
let idx = obj.findIndex(s => s === str);
if(idx >= 0){
count++;
obj.splice(idx, 1);
}
}
return count;
}
//Test:
console.log(getSameCount("abcd", "aad"));
console.log(getSameCount("geeksforgeeks", "platformforgeeks"));
console.log(getSameCount("aad", "abcd"));
console.log(getSameCount("platformforgeeks", "geeksforgeeks"));
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us