how to find repeated characters in a string in javascript
/* Time complexity of solution: O(n) */
const getRepeatedChars = (str) => {
const chars = {};
for (const char of str) {
chars[char] = (chars[char] || 0) + 1;
}
return Object.entries(chars).filter(char => char[1] > 1).map(char => char[0]);
}
getRepeatedChars("aabbkdndiccoekdczufnrz"); // ["a", "b", "c", "d", "k", "n", "z"]