📌  相关文章
📜  JavaScript 查找字符串之间的共同字符 - CSS 代码示例

📅  最后修改于: 2022-03-11 14:47:27.653000             🧑  作者: Mango

代码示例1
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));