Nov 18, 2022

# Solution 1 :

Thanks, I finally solved this question myself

``````function strReplace() {
var text_input = \$('#text-input').val();
var text_split = text_input.split(' ');
var word;
var str;
var final = [];
String.prototype.allReplace = function(obj) {
var retStr = this;
for (var x in obj) {
retStr = retStr.replace(new RegExp(x, 'g'), obj[x]);
}
return retStr;
};
for (var i = 0; i < text_split.length; i++) {
word = text_split[i].split('');
for (var x = 0; x < 3; x++) {
if (
word[x] === 'о' ||
word[x] === 'р' ||
word[x] === 'с' ||
word[x] === 'а' ||
word[x] === 'у' ||
word[x] === 'е' ||
word[x] === 'О' ||
word[x] === 'Р' ||
word[x] === 'С' ||
word[x] === 'А' ||
word[x] === 'К' ||
word[x] === 'Е' ||
word[x] === 'Т' ||
word[x] === 'Х' ||
word[x] === 'М' ||
word[x] === 'Н' ||
word[x] === '3' ||
word[x] === '0' ||
word[x] === '1'
) {
word[x] = word[x].allReplace({
'о': 'o',
'р': 'p',
'с': 'c',
'а': 'a',
'у': 'y',
'е': 'e',
'О': 'O',
'Р': 'P',
'С': 'C',
'А': 'A',
'К': 'K',
'Е': 'E',
'Т': 'T',
'Х': 'X',
'М': 'M',
'Н': 'H',
'3': 'З',
'0': 'O',
'1': 'l'
});
}
}
str = word;
str = str.join('');
str = str.concat(' ');
final += str + "";
}
console.log(final);

document.getElementById("text-output").innerHTML = final;
\$('.btn-copy').attr('data-clipboard-text', final);
}
``````

# Problem :

I want to change not greater than 3 symbols in word, but I have string, which I split. Have you answer for me? (Maybe sorry for my English)

``````function strReplace() {
var text_input = \$('#text-input').val();
var text_split = text_input.split(' ');
String.prototype.allReplace = function(obj) {
var retStr = this;
for (var x in obj) {
retStr = retStr.replace(new RegExp(x, 'g'), obj[x]);
}
return retStr;
};

for (var i = 0; i < text_split.length; i++) {
text_split[i] = text_split[i].allReplace({
'о': 'o',
'р': 'p',
'с': 'c',
'а': 'a',
'у': 'y',
'е': 'e',
'О': 'O',
'Р': 'P',
'С': 'C',
'А': 'A',
'К': 'K',
'Е': 'E',
'Т': 'T',
'Х': 'X',
'М': 'M',
'Н': 'H',
'3': 'З',
'0': 'O',
'1': 'l'
});
}
document.getElementById("text-output").innerHTML = text_split.join(' ');
\$('.btn-copy').attr('data-clipboard-text', text_split.join(' '));
}
``````

Why are you replacing characters with the same characters?

### Comment posted by Olegfunny

It russian symbols to visual similar symbols in english

Ah. But, what is the issue? Your code looks fine. You could probably move

Also, there is

### Comment posted by daniloxxv

Do you have an example of input and desired output?