Como encontrar caracteres repetidos em uma string em 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"]
Odd Opossum