how to calculated repeated occurence in a string in js 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"]