📌  相关文章
📜  在javascript代码示例中从字符串中查找重复字符

📅  最后修改于: 2022-03-11 15:04:15.283000             🧑  作者: Mango

代码示例5
const getRepeatedChars = (str) => {
    let result = [];
    str.map(each => {
      let repeatedChars = 0;
      for (let i = 0; i < each.length - 1; i++) {
          if (each[i] === each[i + 1] && each[i] !== each[i - 1]) {
            repeatedChars += 1;
          }
      }
      
        result.push(repeatedChars);
    });

    return result;
};

getRepeatedChars(["aaabbbkdnndicccoekdczufnrz", "awsfgds"]); // [4, 0]