how to get number of repeated string characters in javascript code example
Example: how to find repeated characters in a string in javascript
const getRepeatedChars = (str) => {
const strArr = [...str].sort();
const repeatedChars = [];
for (let i = 0; i < strArr.length - 1; i++) {
if (strArr[i] === strArr[i + 1]) repeatedChars.push(strArr[i]);
}
return [...new Set(repeatedChars)];
};
getRepeatedChars("aabbkdndiccoekdczufnrz"); // ["a", "b", "c", "d", "k", "n", "z"]