// Вот код
function duplicateEncode(word){
for (let index = 0; index < word.length; index++)
{
if ((word.match(RegExp(`${word[index]}`, "g"))).length != 1 && word[index] != ")")
{
word = word.replace(RegExp(`${word[index]}`, "g") , ")");
}
}
console.log(word);
}
let word = "recede";
console.log(word.replace(RegExp(`${word[1]}`, "g") , ")"));
console.log((word.match(RegExp(`${word[1]}`, "g"))).length);
duplicateEncode(word);
console.log(word);