Search
 
SCRIPT & CODE EXAMPLE
 

CSS

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)
Comment

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"));
Comment

JavaScript find common characters between the strings

let x = "farceus";
let y = "character";

const commonCharacters = function (string1, string2) {
  let duplicateCharacter = "";
  for (let i = 0; i < string1.length; i += 1) {
    if (duplicateCharacter.indexOf(string1[i]) === -1) {
      if (string2.indexOf(string1[i]) !== -1) {
        duplicateCharacter += string1[i];
      }
    }
  }
  return [...duplicateCharacter];
};

console.log(commonCharacters(x, y));
Comment

PREVIOUS NEXT
Code Example
Css :: contain background image within container 
Css :: details transition css 
Css :: nth-of-type(2):before 
Css :: nmap output ip only 
Css :: remove required effect in css 
Css :: flexbox elements 
Css :: display none opposite 
Css :: button hover 
Css :: variable in scss 
Css :: pagination html css how to working 
Css :: ordered list indent 
Css :: chai assert 
Css :: background image causes webpage scrolling slow 
Css :: take out side bar in css 
Css :: WSGI: Truncated or oversized response headers received from daemon process 
Css :: comment in css 
Css :: css font-family 
Css :: promise.resolve 
Css :: flex order 
Css :: why is my css not working 
Css :: scss loop 
Css :: var in css 
Css :: div with specific id css 
Css :: css glass 
Css :: CSS 2D transforms 
Css :: canva 
Css :: abc 
Css :: custom properties css 
Css :: hover.css cdn 
Css :: html display text in alternating coloured panels 
ADD CONTENT
Topic
Content
Source link
Name
2+8 =