+ 1
Please help me based on javascript (characters swap)
Select two characters that exists in the string c1,c2.Replace all occurrences of c1 with c2 and all occurrences of c2 with c1 for example. "bbcacad"
5 ответов
+ 3
"bbcacad".replace(new RegExp(c1, "g"), c2);
https://code.sololearn.com/WtM4qrG4t7yk
JavaScript String replace()
https://www.w3schools.com/jsref/jsref_replace.asp
+ 2
let s = "bbcacad";
let r;
r = s.replace(new RegExp('b', "g"), '#');
r = r.replace(new RegExp('a', "g"), 'b');
r = r.replace(new RegExp('#', "g"), 'a');
console.log(s, r);
+ 1
Thank you
+ 1
In above example :bbcacad
That we can execute like aacbcbd
And aabcbcd
0
I will try this